First of all, you might be thinking of doctors like neurosurgeons. Less than 1% of practicing physicians in the US are neurosurgeons, and some neurosurgeons make as little as $250k (often ones with special academic appointments). Not all of them make $1M/year or even $700k/year.
Second of all, you might in general be overestimating doctor compensation. See this report:
http://www.medscape.com/features/slideshow/compensation/2015...
Primary care doctors earned an average of $195k in total compensation. Half that is $97.5k. There are many developers who make more than that -- certainly far more than .1% of developers. That is, in fact, the median pay for software developers:
http://www.bls.gov/ooh/Computer-and-Information-Technology/S...
Granted, you did say specialized doctor, and we see from the MedScape report that they make $280k on average. Half of that is only $140k. There are fresh college graduates who make more than that in total compensation. I've even known relatively new developers making $250k once bonuses and vesting stocks are taken into account. Either way, $140k in total pay is not uncommon at all for an experienced senior developer. Again, certainly far more than .1% of developers are in that income bracket.
Finally, and perhaps more importantly, I think you might underestimate the difficulty of becoming a specialized doctor. It's certainly much harder than becoming an average programmer. The educational requirements are vastly higher and more rigorous. The debt load is in the six figures for all but children of the rich. And the time investment is at minimum 11 years (4 undergrad + 4 medical school + minimum of 3 residency). But since we're talking about specialized MDs, the residency will actually be longer than that, as long as 7 years for a neurosurgeon, plus an extra 2-3 for a fellowship if desired. After all that, the doctor will potentially work twice as much as the programmer.
It's not fair to compare the average heart surgeon to the average programer, because the heart surgeon is by definition vastly above average among doctors in both education, grades, and pay. It would really only be fair to compare the heart surgeon to, say, a senior engineer at Google (or similar), where a total compensation exceeding $250k is common.
As for lawyers, many law school graduates I know don't even have a job. The days are long gone where a law degree was automatically a golden ticket. It's certainly true that the top lawyers make a large amount of money, but becoming a partner (say) at a large firm is just not comparable to becoming a programmer. These days, it's like winning the lottery.