People are very often wary of people different from themselves. And as a country identifies itself as something and then outsiders challenge this definition of themselves, a natural guard or harshness takes effect. This can be seen as a pack mentality of sorts. This, however, does not mean it is morally correct or a benefit for the country for immigrants bring new ideas and perspectives to a country that allows it to prosper and grow.
My experience is that people in smaller, more isolated, less economically successful communities are typically more xenophobic than those in the more cosmopolitan metro areas.
For various reasons, immigrants tend not to spread out evenly: not having ties to any particular area of the country, they'd be crazy not to pick an economically successful area with relatively low levels of xenophobia, or at least a big enough community to be able to insulate oneself from xenophobia somewhat, and this becomes self reinforcing both for locals and for new immigrants, since more exposure to a diverse set of immigrants tends to reduce prejudice and immigrants often want to move to a place where there's at least somewhat of an established community of people from the same place of origin.
One fundamental problem with humanity is our natural tendency to put people into different groups and form opinions about the people in those groups. We tend to prefer people who are in the same groups as us compared to people who are in different groups than us. Therefore, for example, Americans automatically tend to prefer other Americans and dislike foreigners, for no real reason. This is true of every country and every region in the world.
Throughout the history of the world, many countries have been harsh toward foreigners. This seems to come natural to people. Societies must work to evolve and adapt to changing demographics by becoming more open minded. America has traditionally been known as the great melting pot--accepting people from all over the world. However, America has also had its share of discrimination too.