What you are missing is that many of the patients who come to these hospitals are not even Medicaid or Medicare recipients. There is no contract at all; they are simply treated for free. And they arrive carrying diseases not present in our native population, or with conditions that would have been minimized with American-style medical care but are now catastrophic.
It's certainly true that illegal aliens are only part of the problem. We have our own home-grown problem patients here. But at least the home-grown patients have Medicaid and sometimes Medicare coverage that helps compensate the hospital to some small degree; the foreigners do not.
I understand. However, can you cite a law - either State or Federal - that requires this?