I don’t think that is really true. Both of the latter are apprenticed-based but otherwise easy to enter, and we are only having a shortage now because of the housing crash in the previous decade. Tech has been booming almost continuously now since the beginning of the century.
But tech work has many force multipliers, unlike those other careers. The right framework, or library, or product can make the work of one programmer feel like the work of 10, and that’s what many people do not take into account.
Also, demand for programmers at the salaries programmers want to work for is not that strong. Many companies that want programmers want them for a lot less. This cheaper labor can be harder to find, but can be substituted in many ways such as using an “As a Service” offering or scooping up a pile of Indians from Kolkata.
It is never that easy. Frameworks are kind of force multipliers until you want to do something new, then you are stuck.
Demand for programmers is high even at high salaries (depending on experience of course). The average google programmer pulls in around $1 million in revenue, which covers their overhead well enough.
Revenue an employee makes for a company doesn't need to correlate with salary, that's based off market demand. If that's what people want they should work in sales on comission.