This is a fair point, one of the strongest arguments to be made for very specific work visas.
The problem, then, is how to allocate those visas without suppressing the market signals that would, long term, bring pay into balance.
All kinds of differences of opinion on this one from reasonably people. I tend to take a very suspicious view point on government intervention to control prices. I look at high level tech jobs, and to me, it looks like they generally require majoring in the hardest undergraduate subjects, and often (sometimes preferred, sometimes required) require gaining admission to top programs with high standardized test scores and GPAs, and finishing grad programs with much higher attrition rates than elite med, law, or business schools (UCSF's medical school attrition rate is below 0.5%, whereas top PhD programs often have attrition rates of 50%. MS programs are harder to find data on - all I could get was aggregate (rather than elite) and it was behind a pay wall, but I believe it was 25-30%).
Although an MS is shorter than a med degree, and a PhD is about the same amount of time (considering residency), keep in mind, we're also talking about a "shortage", so I think it's reasonable to take a generous view of what compensation should be. I'd say people with grad degrees in math heavy STEM fields - even MS degrees, should probably be on a par in terms of salary and career stability with medical specialties before we should be talking too seriously about a "shortage" that wouldn't simply be explained by uncompetitive wages and working conditions. So overall, if it's relatively straightforward to earn over $300k a year with a grad degree from a top 20 engineering school, then I'd be more open to the notion of a "shortage". Otherwise, I'd say that people are just making economically rational decisions to stay out of STEM jobs, considering the skill and academic ability required to get grad degrees in this field.
I know that would cause sticker shock, but I'd say that if the average mid-career industry salary is much below 300k for these degree holders (to say nothing of job stability), I have trouble believing it isn't a crutch to avoid competing for workers who can participate freely in labor markets.