Alex Gunz has an excellent overview of what psychologists have found out about this important question. The article starts out with personality-based theories (for example, "New research ... [shows] that people who are very low in the commonly measured “openness to experience” construct seem to be more likely to be both right wing, and prejudiced."). But it moves quickly to the situational causes, and this is where it gets scary. It appears that it's easy to make us -- yes, all of us -- create "Those Bastards Over There" and start hating them. It has a nice discussion of the situational forces -- competition, upbringing, culture, situations that make you feel low, etc, with vivid examples from clever experiments.
Here's an excerpt, that has a pretty positive message:
Prejudices, it seems, are more malleable than the people holding them tend to think. The end of World War II saw Germany and Japan switch rapidly in the Allies psyche from terrible enemies, complete with derogatory nicknames, to stalwart friends, demonstrating that even those prejudices that had been chiselled, literally, into granite, aren’t. Ever since Sherif's experiment, psychologists have wondered about the best way to help such thaws along.
Recently psychologists Thomas Pettigrew and Linda Trop (2006) gathered the results from hundreds of studies on this question (covering thousands of people), and used complex "meta analysis" statistics to take a powerful new look at the collected results. What they found is strong support for the ‘contact hypothesis’ - that personal contact between group members helps improve feelings. Contact even works substantially better when a number of conditions are present. From what you've heard so far, you won't be surprised to know that it helps to have a shared goal to work towards (like getting your bus unstuck), and that it is good to have a shared outgroup to rally against ("stupid vandals"). Other things help too, though, such as having the contact occur on an equal footing, with no group having higher status than the other.
As they say, read the whole thing. Don't forget to read the kicker in the final section!
* * *
Thanks to the ever-excellent The Situationist for the pointer.