Resident doctors are doctors, exactly as junior SWEs are software engineers.
(UK doctors have for some reason long objected to 'junior' and recently become 'resident doctors' over exactly this. All the more confusing - throughout and still there's been 'Senior House Officers', because 'house' used to be what it was called, like US residency, doing house, there were junior and senior house officers, so why not just revert to that? Who knows, but now they're all resident doctors - and some of which are senior house officers - until they're registrars/consultants, and they're happier with that than junior doctors.)
One answer would be to raise GP salaries, but that's difficult, especially if you're self-funding residencies and already paying out the nose for specialists and other inflated expenses deemed necessary in modern healthcare systems. Kaiser California imports medical school graduates from abroad for their in-house residency programs, which is presumably cheaper than raising salaries to draw more US resident candidates.
Kaiser arguably points the way forward. As an HMO--a vertically integrated healthcare system--there's greater financial incentive to self-fund residencies. When insurers, hospitals, and doctors are all at arms length from each other, the financial incentives don't align very well, thus the "need" for outside funding (i.e. the government) of residencies.
Note that unfunded residencies are also a thing, where the resident is responsible for sourcing the funds for their salary and expenses.