I'd be interested in seeing a survey on how many people currently working on a PhD believe it will lead to a tenure-track job. I'm a PhD student now and I'd be skeptical if it were more than 25% of people in my department, for example. (I myself have no interest in tenure-track jobs.) There does seem to be more demand for the jobs than there are jobs, but I think in the STEM fields I am familiar with, people are more realistic about what types of jobs they are qualified for. It helps that STEM fields have more options than the humanities, for example, too.
Also, my guess would be that many PhD students realize that they won't ever get a research job, and they treat this as their opportunity to do research.