I think it is because the government finds it valuable to have a well trained workforce to take care of its Medicare patients. Do you want physicians to pay for the opportunity to work for hospitals taking care of their patients?
Should the government pay me to study computer science? Should they pay for there to be more computer science training slots in universities? CS is also a valuable workforce, with massive shortages in the US. I don't really think the govt should pay for me to train, or pay to improve the number of educational spots.
At the same time, it does seem like medical internship conditions and pay are ridiculously terrible, underpaid, way overworked.
PhD programs in CS are generally paid, largely by the government via orgs like the NSF. I think this a good thing; you would have many fewer PhD grads otherwise and I think they are generally an asset to the country and the companies they work for.
I don't see why they shouldn't fund more CS and STEM spots and universities in general. They will probably see a good return on investment. AFAIK higher education is subsidized in other countries but I'm not super knowledgeable about that.
On second thought maybe it would make sense to only subsidize the residency programs that are financially unsustainable but necessary, like family medicine or non-subspecialty internal medicine. Downside to this could be that hospitals could choose to not have residents and exacerbate the physician shortage.