The following quote comes from the history textbook titled American History: A Survey,
The Chinse in American didn’t accept the new law quietly. They were shocked by the anti-Chinese rhetoric that lumped them together with African Americans and Indians. They were, they insisted, descendants of a great and enlightened civilization. How could they be compared people who knew "nothing about the relations of society? White Amercan,they said, did not protest the geat waves of immigration by Italians (“the most dangerous of men," one Chinese American said) or lrish or Jews.They are all let in, while Chinese, who are sober,are duly law abiding, clean, educated and industrious, are shut out.”
I understand that historical events are extremely complicated. But I am here to ask a simple question as if I were only five years old. What are main causes behind the treatment of those Chinese immigrants?
They were less poor than Irish, they were as paganish as Japanese, and indeed they came from a relatively more advanced civilization than lot of indigenous cultures.
ELI5 is a bit tough, since it's such a huge topic, but I'll do my best to keep it simple.
At the end of the Second Opium war, there was a treaty signed between China and foreign powers. It was called the Treaty of Tientsin. It's important, but the more important part or your question is actually an amendment to the treaty. This amendment was the 1868 Burlingame Treaty, signed between China and the US. The Burlingame Treaty allowed for free migration between the two countries. It was short lived, but it was the first thing that really allowed large-scale movement of Chinese citizens into the US.
One of the reasons it didn't last long is that it quickly resulted in large-scale migrations of migrant-workers (not immigrants) into the US, particularly in places like California. Given the disparity of how much a dollar could buy in the US vs in China, especially in places like the Pearl River Delta where the majority of Chinese migrants were coming from, Chinese workers were willing to work for far less than others in in the western US. This led to a lot of resentment, as you can imagine. Not just in terms of railway work as is well know, but restaurants and other industries as well.
Because of this, in California there was a growing sense of anti-Chinese sentiment. In California this was strongest, and quickly was written into law. One early piece of legislation was the so-called Anti-Coolie Act of 1862 which put a tax on Chinese doing business in the state, and before that another tax in 1852, and then an anti-immigration law in 1855.
There were so many more small steps in push working toward total banishment. A few of them are as follows, again trying to keep this simple:
The 1875's Page Act, pushed by the largely-white labour unions, meant to be a means of protecting the American labour force from wages that other people couldn't compete with. This was done because the non-Asian population in the US at the time felt that these foreigners were coming and taking their jobs, a sentiment that may sound familiar to Californians today.
But importantly, the Page Act did not outright stop Chinese migration. Instead it was primarily worded to prevent people from being brought against their will. But also it applied to "any subject of China, Japan, or any Oriental country". It was a lose definition of who it applied to. China and Japan are clear enough, but "any Oriental country" can be taken pretty broadly.
1875 also saw a Supreme Court case which determined that immigration laws were not the domain of the state, but instead could only be enacted by the federal government. This was in response to California's tendency to limit immigration, but of course taking this decision out of the California government's hands didn't actually do anything to reverse the trend, and California was in no way alone in their attitudes toward the Chinese, and neither was America.
A few years later, things became formally much more restrictive. Leading up to this there were already significant restrictions places on East Asian immigrants such as not allowing them to naturalise, and also limitations on what type of business they could do. 1879 saw the "Fifteen Passenger Bill" which only allowed up to 15 Chinese passengers on any ship coming to the United States. President Hayes was also strongly opposed to immigration (which he called invasion) of non-whites (which he called the "weaker races"). Still, he ended up vetoing it only based on it conflicting with previous treaties and therefore not actually passable, despite a large majority in the House and Senate supporting the bill.
Then In 1880 the previous treaty between the Qing and the US was modified with the Treaty Regulating Immigration from China, limiting all blue collar workers from immigrating, not just prostitutes and forced labourers as has been the case before. Quoting from the treaty:
the Government of China agrees that the Government of the United States may regulate, limit, or suspend such coming or residence, but may not absolutely prohibit it.
That's the wording written by the US, not China, in case it wasn't clear.
Then in 1882 things got worse as a law was signed into effect in the United States that effectively limited any immigration from East Asia. This is known as the Chinese Exclusion act, which was in effect until it was repealed in the 1940s. It was originally a temporary move but it was later made permanent.
1892 saw a renewal of the Chinese Exclusion act as the Geary Act, which added that all Chinese arrested will be assumed illegal immigrants unless they can give solid proof that they arrived before the passage of the previous acts. What constituted as proof was a certificate of residency.
There's way more. But the gist is that the non-Chinese workers were unwilling to be paid as little as Chinese workers were willing to work for, and Chinese restaurateurs were charging less for good food thus seen as a threat by non-Asian restaurateurs, people acted exactly as they pretty much do now about it.
It's also relevant to your question why Japanese people — also listed in some of the exclusions but not all — were less often the target. The two main factors were that Japan had already begun actively developing starting in the 1850s when forcibly opened to the West, and also there were just so many more Chinese than Japanese at the time, as today. It's not that Americans were more positive to Japan so much as they were just less aware of Japanese people as a unique threat to their situation. Japanese people also endured all of the same crap Chinese people did, and in some times and places, worse. Sugar cane workers in Hawai'i being a good example.
So yeah. Chinese migrants were treated so badly because people were already xenophobic and then economics became an easy tie-in to their "economic anxiety", to use a modern term that often comes up in today's equivalent of the discussion.
I can expand on any of this if you're interested. I've kept it short(ish) just because of the ELI5 request. But feel free to ask if you have more questions.
See also:
Gyory, Andrew (1998) Closing the Gate: Race, Politics, and the Chinese Exclusion Act
Lee, Erika (2003) At America's Gates: The Exclusion Era, 1882-1943 <-- this one is an easy read and quite informative, if you do want to read more.
Note: Full disclosure, I've adapted some of this from older answers I've given here.