It's not just money - the ability to educate the rest of the world's elites is a form of soft power.
For Master's degree it makes sense because the students pay tuition. For most PhDs, the students don't pay tuition and get an additional stipend, so it doesn't make sense. Plenty of (most?) PhD grads stay but we are currently paying international students to do their PhD and then provide very little incentive for them to stay afterwards.
Seems like you understand the point after all :)
US tertiary education is the perfect export good: Like other intellectual property, it's almost infinitely fungible, and parents from all over the world will part with staggering amounts of money for it.
The quality is definitely high, but the markup compared to other countries' universities is something else.