There were two main reasons for this.
First, there was an economic aspect to this treatment. American people felt that Chinese immigrants were coming in and taking jobs away from them. This feeling was especially strong during economic hard times.
Second, there was certainly a racial aspect to this treatment. All major waves of immigrants were treated at least somewhat badly, but the treatment of Chinese was worse than others. This is because Chinese were seen as racially inferior to all types of white people.
For these reasons, Chinese were treated badly and further Chinese immigration was banned in 1882.
Around the late 1800's the civil war had end and the economy was heading into a depression. Jobs became few and wide spread. Imagine the surplus of men after getting out the army that secured them with pay now they were alone without as much as a penny. Then imagine those who depended jobs that were need for the war would now no longer be necessary. So there were not too many jobs for either of the groups of people. And many began to turn their frustrations to the Chinese because they saw them as threats to job opportunities. Because of this tension there was law called the Chinese Exclusion Act the prohibited the Chinese from immigrating to the US.