why aren't there more residency spots? Why can't people who need to do residency be forced to go to a (more) far away city that has a lack of doctors and be trained there?
Because residency programs are very difficult to operate and require a level of staff that not all hospitals have access to.
The issue isn't with the supply of graduating students, it's with the number of residency spots.
This year 95.3%[0] of graduating students matched to a residency program. Out of 18.5k applicants, only 17.5k matched to an available residency program.