Why can't everyone who is doing academic research/teaching post-PhD be eligible for a tenure position, if they work hard and publish enough high-quality papers?
Supply and demand: tenured positions are pretty much lifetime positions. Not in the sense that the positions are fully guaranteed without having to work towards them once obtained, but in the sense that, absent misconduct or complete failure to meet expectations, there is a job there.
There are way too many PhD graduates in most fields for them to all have a permanent position in academia. I suppose you could start every researcher on the tenure-track and then make many more people fail to get tenure, but I don't see that as an appreciably better outcome than limiting tenure-track positions: there has to be a gate someplace. "Tenure-track" is really just a probationary period in which candidates demonstrate they are suitable for tenure.
Like hiring for any position with many applicants, there will be imperfections in the hiring process. There are too many "qualified" people, too many difficulties in determining objectively which of those qualified people are "best," and too few positions to put them in.
edit to address clarification in a comment:
I don't understand why it would be less desirable to have more people failing to get tenure, as opposed to the 2-tier system that seems to exist. Why not put that 'gate' at the point where a tenured position needs to be filled, and then decide? Where is the incentive for the institution to not want to keep their options open as long as they can? Surely that would also be better for the majority of postdoc academics, who are currently on non-tenure-track and (apparently) locked out?
I wouldn't see them as "locked out" necessarily, there are lots of possible situations: a post doc (in some fields labeled a non-tenure track assistant professor; the distinctions are small though I believe more likely to include teaching for the latter) is someone who hasn't gotten a tenure-track job yet: their "clock" hasn't started yet.
Or, they are someone like me, with a semi-permanent soft money academic job, who likes research but didn't want all the extra stresses of finding money and earning tenure that a tenure-track position requires, and who is willing to take the difference in pay and independence.
Or, they work in a field like medicine where their primary responsibility is as a clinician, but they also teach, and they don't do enough research to fit their institution's standards for the tenure track.
In experimental fields, hiring a new tenure-track assistant professor is a big financial investment due to needed lab space, equipment, etc. Non-tenure track positions like post-docs let people build their research career in someone else's lab space and develop their independence more gradually.
The other side of the coin are the primarily-teaching adjunct-type positions; these positions are a tough topic that's been addressed elsewhere on this stack, but in summary they exist because people are willing to take them when they can't get another job (either to keep the possibility of an academic career alive, or just as a paid job), and they are a massive cost savings for universities. Whether that is ethical or not is unclear, but eliminating them would likely reduce the number of academics employed even if it increased the average salary/benefits.