That's in no small part for the benefit of the US university, though, not just a personal benefit to the student. In some sense, grad students are a bit like faculty in that they are "part of" the university and contribute to its prestige and academic output in a way that undergrads don't. Not providing them with grants, and thus decreasing the success in recruiting them, would lower the prestige of the university and the accomplishments of its PI's labs.
Undergrad selectivity/quality does affect rankings too, but it doesn't probably doesn't affect faculty recruitment (except for the rare faculty that care a lot about teaching), but grad student recruitment absolutely does. Even a pathological case of a selfish PI who doesn't care about the students themselves and just cares about his own prestige/publications is going to be very interested in the quality of grad students coming in each year. Even state institutions that favor in-state heavily for undergrad generally don't do so for grad school.
Likewise, having an international faculty and grad student base is typically considered an ipso facto positive thing for a university, which has a inherent role of exchange of ideas and thus also of the people that hold them. Some countries even offer grants to arguably more generous grants to foreign students (ex. the MEXT scholarship in Japan) for that reason--having quality international students is an essential part of the prestige of their unis and one that they by definition can't improve through their own students.
Re: your point about costs, even with tuition grants, the costs of grad school in the US due to double effect of the strong dollar and high cost of living is likely to be just as high as a domestic school with higher tuition but potentially free room and board, and much lower food/transit/etc costs.