you forget all the costs paid to faculty, administration, support staff, insurance, increased in unecessary tests, etc, which adds up. And I am not saying that hospitals don't generate revenue from residency programs, what I am saying is that the productive index of a resident as defined by the ability to generate revenue minus the costs of traning and supervising and supporting that resident is negative. And most of the excess revenue generated by residency programs is baisically spent subsidizing the poor re-imbursement of the medicare and medicaid payments that hospitals recieve for services otherwise, allowing hospitals to actually stay open even though most teaching hospitals see a disproportionate amount of medicare patients. Other revenue goes to research stipends for faculty and such.
Fundamentally, no one is getting rich or has there hands in the cookie jar when it comes to residency programs, after all, private practitioners make more money, not less, when they don't have residency programs in there hospital because they typically do not have the same obligation to see medicare and medicaid patients.