The pattern of discrimination and dislike of immigrants has repeated itself almost identically over the years. The main reason is cultural. That is, so called "natives" who were already living here for a generation or more, had their own culture based on Christianity (usually Protestants) and the English language. Large numbers of immigrants made them feel as though their culture and heritage were threatened. This was a myth as immigrants time and time again had assimilated by the second or third generations.
Sometimes it has been for racial reasons, as immigrants from Asian countries especially were easy to discriminate against, while the Irish, for example, as Caucasians, blended into the population in both language and appearance in just one generation.
Lastly, there is a myth that immigrants take jobs "Americans" would have otherwise. The truth is that they almost always work the more difficult, dangerous and low paying jobs other Americans are unwilling to do.
The most usual reason for Americans to hate immigrants is because the immigrants are too different in some way that seems important to Americans at the time. This tends to happen more when there are more immigrants, and especially more from one region or country.
For example, immigrants have been hated when they were too different in terms of religion (Catholics and Jews) or in terms of economic status (too many poor ones).
In addition, Americans have tended to believe that immigrants do not want to assimilate and become Americans. This is a recurring theme in all major waves of immigration.
I think the answer is simply "human nature".
While I don't think that Americans have always "hated" immigrants I do think it's fair to say we have had a double standard towards them considering we are all immigrants save Native Americans.
But alas it is human nature to forget that you are an immigrant, to get yours, and then feel threatened when you see others taking a piece of the pie.
Hopefully, most American's treat legal immigrants fairly, and illegal immigrants with dignity.
It is important that except for the native Americans, all citizens of America are either immigrants of descendants of immigrants.
The hate against immigrants is really the tension that exist between people of different groups in close contact because of two reason. One is that as each group tries to better its position, the other group feels that the group that has gained has done so by taking away some thing from the other. This is, of course, not true in most of the cases. Most certainly it is not true in case of USA. The current level of development of USA would not have been possible without contribution from all the immigrants of all origins who made USA their home, and their descendants. As a matter of fact even today USA stands to benefit from immigrants with some specific background and therefore the government has a policy of attracting and encouraging people from other countries with such profile.
The second reason for tension between groups from different regions and between people who immigrated long back and those who immigrated recently, is because of cultural differences. Each culture has certain ways of living and behaving that the members of the society get used to. Also each culture defines in its own way what is right and wrong, and what is valuable. These differences in ways of living, beliefs and values, make people from each culture look down upon other cultures and the people from those cultures.
When it come to the question of fair treatment, the law is very fair. But law by itself is not enough. Not every action of individuals is controlled by law. Also there people with prejudices may, consciously or unconsciously, act in contravention to letter and spirit of law. A graphic account of how these prejudices can subvert the provision of law is depicted very well in a book often featuring in eNotes questions - To kill a Mockingbird.
People tend to turn their ignorance of other people into hate and violence. People can be fragile in their thinking when it comes to different people in the manner of dress, customs, religion, and philosophy. When people do not understand something, such as when someone is willing to do a job that they themselves would not want to do, people tend to form their own ideas of how unusual ands strange people can be. This is quite an unhealthy attitude to have.
This unhealthy attitude towards others forced people into their own communities and created different pockets of immigrants in large cities.