From a UK perspective, it's a matter of market forces.
Originally (pre-1900), universities were mostly funded by fee-paying students. Costs were high, but only students from rich families could afford to attend. Places were limited mainly by the number of rich people. Ability was not necessarily a pre-requisite. There were a large number of institutions which funded people without money but with significant skills, but they were a definite minority.
Then the government started funding universities - especially after WWI, there was a strong feeling that everyone (all men anyway; women at universities is a separate issue!) should be given equal opportunities to advance themselves, and universities changed to being mostly funded by government (with some extra from the private sector). Cost to students was zero, but government funding was limited. Every student takes money to teach, so the number of places was limited to what the university could afford. As a result, university places were selective, and only the most able could attend. (Some universities still allowed rich kids to buy their way in, but they were a minority.)
In the 1990s, this changed again. For various political reasons (which I won't go into), government grants for living whilst studying were removed, universities received funding based on the number of students regardless of the value of the courses to the student or the country as a whole, and universities were allowed to charge tuition fees. Now every student was a cash cow, so the incentive was for universities to admit anyone, of any ability, and milk them to the maximum. The majority of students receive no benefit from their courses compared to the experience they would have gained from three years of work, and are tens of thousands of pounds in debt.
And that's where we are today.