Regarding the full-paying foreign undergrads, their tuition contributes towards the costs of the university that are shared. American students, especially at middle-ranking public schools, are hurt when schools lose their funding.
Regarding the "racism against Americans," there is no such race, and if there were one it would not explain research productivity. What would is the self-selection of who will go across the world to study something technical, the much better high schools in other countries, and in the mere fact that the rest of the world is a larger talent pool than the US. It is easy to think of reasons.