There's some good reason to think that residencies are profitable: in 2019, 550 of them were auctioned off for $55 million in a controversial bankruptcy case.
They are taxi medallions to newly graduated MDs but not to the hospital. Without a residency slot MDs often times are relegated to a lifetime of med school debt servicing.
It is not that the residencies themselves are profitable. It is that medical schools need to be able to provide residency slots to their students to have an effective program. Definitely an issue for newly formed for-profit medical schools.