Second, non-profit doctors get their loans forgiven. Are you suggesting they should get loan forgiveness and make the same gigantic salaries for-profit doctors make?
Since it seems like you want to end the institution of lawyers entirely (which seems a completely unworkable hypothesis because it assumes that the disabled, uneducated and children in this country would be able to self-represent and provide justice for themselves), I won't use that example as I'm not here to debate the utility of lawyers.
However, you DO understand how the Federal Public Service Loan Forgiveness program works, RIGHT? You must work for 10 years in a nonprofit and you must spend those 10 years making payments on your student loans every month (120 payments, no gaps). You must be in good standing with your loans. The only loans that qualify are federal loans, and specific federal loans (not Federal Family Education Loan or the Federal Perkins Loan.)
The average doctor has $166,750 in med school debt alone. This cannot be all put into qualifying student loans. This means even if you are making $40,000 a year (your suggested wage that would be fair for anyone working at a nonprofit, regardless of education or skill), you would still have $300 in income-based repayment to make every month on the loans that qualify PLUS loans that don't qualify. Which means paying 15% of your take-home income each year to make no actual progress on your debts, only pay off interest. Also the loan forgiveness program is so new, very few have successfully used it and those who have tried have had a lot of trouble with working through it.
So essentially, if you're saying doctors in rural poverty clinics should make $40K a year (which would be less than they make as a RESIDENT to be clear) then only people who have enough wealth to not take out private student loans should do that work. That's then excluding the people that actually come from those communities (because they wouldn't have the means to pay out of pocket for med school) from doing that work. There's a ton of evidence that people from rural low-income communities make the most effective medical practitioners in those communities because they foster trust among their patients and understand local customs & practices.
I'm trained as an economist, so of course I believe skills should be compensated on a scale relative to their demand, so take that bias into account. However, I abhor when people think that "nonprofit" should mean no one should get paid. Or that work in the social sector automatically be compensated below 50% of the market rate for the same work. Making $60K is not a "get rich quick" scheme for any social sector employee, any more than it is for a corporate employee who makes the same. The idea that a banker deserves $60K more than a social worker who deals with physical threats and handles the most delicate and violent members of society each day or a teacher who works with youth in danger of dropping out to help them overcome the barriers & abuse in their lives is simply offensive to me. And this is coming from someone who lived in voluntary poverty as a social worker for years and left to move into the "high hog" of Americorps wages.