I understand what you're saying and largely agree. Most of what I've said here relates to my DW specifically. I think she's underpaid because I believe society places too low a value on the contribution good teachers make. And, yes, she could go elsewhere and make more but, along the lines of what you've said, she's good at what she does, she enjoys it and she finds it rewarding.
You believe she's underpaid, but she apparently believes she's being fairly compensated (when she includes all factors: pay, vacation, health care, retirement, security, and the intangibles of believing she's helping people, helping society, etc). Obviously, it's the total compensation that people use when they evaluate their worth, and their ability to get higher total compensation (to include those intangible things) elsewhere.
The fact that she keeps working there is the bottom line and tells the entire story--she thinks it's the very best she can get from a total compensation perspective (or at least, the trouble, "friction," and uncertainty of finding something better make doing so unrewarding), so she's staying put. That's probably best for everyone, including her lucky students.
While society gained when we broke down gender stereotypes and women began working in many areas previously closed to them, the US K-12 education system lost a lot. In former times, there were fewer fields open to talented women, and so we got exceptionally well qualified female elementary school teachers at a big discount. Entire generations of Americans benefited from the talents and efforts of these women. On balance I surely don't think it's worth "going back" to that way of thinking (if for no other reason than their talents are being put to better use, according to the market, these days), but it's one of those rare cases where discrimination of a type we now view as odious and illegal had a silver lining of sorts.
The bigger question: is society (and the market) good at assigning value to all things, or are there areas where it falls short? For starters, I'd argue that markets, voters, and individuals don't do a great job at making early investments for later rewards (and this includes investments in education). I don't have a better replacement system than the markets, but I suspect the answer lies in somehow accelerating the anticipated effects of future market forces so buyers, voters, etc react to them earlier (when costs are lower). An idea we've discussed here earlier along these lines is ERD50's slowly escalating gasoline tax--we know oil is going to get more scarce in the future, so maybe accelerating the price rises now (and using the $$ to offset other taxes) will help us make prudent investments and changes earlier. Of course, this idea would open the door all kinds of shenanigans and "social engineering", so maybe the cure is worse than the disease.