The argument that a licensing requirement constitutes a legal cap is silly, otherwise you have to say every licensed profession is capped.
It sounds like those organizations are capping it, not the law. And they could presumably change that decision without any change to the law.
The number of resident slots is limited because the gov't must pay a fixed amount to the hospital for each resident and that funding is capped. This is an intentional construction. More on that here: https://www.openhealthpolicy.com/p/medical-residency-slots-c...
Edit: this comment must have made a lot of people mad, because three other people responded within 5 minutes lol
don't think many other entities besides the federal government have a ton of incentive to fund residency. and the federal government does have caps on residency slots
[1] https://slate.com/technology/2005/06/private-funding-for-res...
Interesting related thread: https://www.reddit.com/r/Residency/comments/a01cfr/funding_y...