According to J.Simons (Fields medalist turned hedge Fond billionaire) especially in STEM fields Schools compete with tech companies for talent and can only offer much worse compensation.
The other thing is that in the 50-70ties the number of people that studied in preparation for and went to college was somewhere between 8-15% (continuously rising) it is much easier to teach smart students with few good teachers than to prepare basically everyone for college.
In Germany my parents almost exclusively had PhDs as their teachers, now 60% of all students prepare for university and we have a shortfall of ~20000 teachers with half of the STEM education majors going to industry.