Student loan debt isn't even a big factor in this because of the sheer size of the salary gap. $500k loan gets paid off fast when you make $300k+, and you get that salary for life whereas the loan only weighs you down for the first 5-10 years.
[1] https://www.healthcareers.nhs.uk/explore-roles/doctors/pay-d...
https://www.nerdwallet.com/article/small-business/how-much-i...
I'm not at all shocked someone who cuts people open and removes or adds objects has a high liability insurance.
I have no source for this, but blaming medical system costs on liability insurance feels like a way of blaming the patients instead of the system. "If only greedy people were not trying to get rich quick off lawsuits."
Compare that to a programmer, assume 4 years of undergrad, and then you get out making $100K easily - especially if you were a very smart student, probably much more (i.e. someone that was smart enough to be a doctor or a programmer), not even accounting for raises and inflation, 6-7 years at $100K and also assume 400K for med school loans and the programmer is already almost $1Million ahead of the doctor at year 7.
Over the long haul the doctor will likely do better, but it will take years to catch up once you factor in the huge costs a doctor has vs a programmer - I for one am glad only really smart people can become MDs.