So there's two separate allocations here - the number of training spots per program that is allowed and the number of spots that is funded. These are often discordant.
When the ACGME accredits a residency program, the RRC (residency review committee) for that specialty reviews the resources available to the program and sets a maximum # of residents it can have. This consideration includes the # of faculty members, the volumes in clinics, and the available # of procedures/beds/etc in the hospital. For example, they'll look at the total number of clinic visits in all of the academic clinic and say "if you had a resident in every clinic, even the ones that aren't currently covered, how many residents would that training volume support?". For surgical specialties, often specific cases are the holdup here - Ob/Gyn programs are often limited by hysterectomy numbers for example. When programs are accredited they basically can ask for whatever complement of residents they want - and if the volumes support it, they'll be approved for that.
The second allocation here is actually paying the residents. Funding from medicare is typically allocated on an *institutional* level, not to individual programs. So if University of XYZ Hospital has been allocated funding for 200 residents, and their programs have a total of 300 spots between all residents of all years, the University can allocate the medicare funds however it wants. Now, there's funding from other sources (Medicaid, state funding, VA funding, internal funding) that may be allocated differently - and it may be required to go to one kind of program or another.
If there's more spots than there is funding, the hospital system can choose to fund the extra spots internally - or just leave them empty. The ACGME accredited spots are a maximum, not a requirement. For a personal example, my fellowship program (which typically had 4-5 fellows total between the 2-3 years) was approved by the ACGME for up to 8 total fellows/year due to the number of faculty members and the clinic volumes. If they had the extra funds, they could have doubled the size of the fellowship - but they didn't, so they didn't.