Second, most people aren't rational economic actors and even those who are have a myriad of objective functions.
Some common reasons people stay when they could get much higher paying and lower stress jobs:
1. Immigration.
2. Work life balance. Not unique to academia, btw. I know ex-FAANG SWEs who make $70K/yr because they can get the job done in one or two days a week from a van and want to spend most of their life in the mountains.
3. Immigration.
4. Some people actually enjoy teaching and view it as a life calling.
5. Immigration.
6. Ageism. A 50 year old who spent 20 years in academia is going to have a hard time getting back into industry.