For some reason, residencies are paid by the federal government. Not sure of the history there - I find it hard to believe a resident doctor is a net-loss for the hospital system. Either way, I can't find any legal cap on number of residents - only a cap on funded slots (ie, a hospital could hire more residents and pay them out of pocket).