A very cynical take I've heard is that it acts as a class filter, just as is higher education. A somewhat less cynical view is that it's favoritism and trust, just like how people from certain top schools tend to hire those from other top schools with less harsh judgment.
However, I am really more interested in the apparent paradox that most internships present, in their accessible to students, people already in a better-off position to enter the professional world. But having the majority of them being inaccessible for those not in school, who actually need more help to get in a similar good standing for a career. In this comparison a student is getting a "double serving" of benefits. Is it as simple as risk factors that companies don't want to take into consideration with self-taught people?
Companies may legally have unpaid interns on staff.
But internships must be part of a credentialed academic program.
Otherwise, minimum wage laws apply and having unpaid staff is a violation of labor law.
For context though, the US has a very accessible system of higher education via community/junior colleges.
Also for context, the ability to work unpaid in a professional setting has always had a strong correlation with class. It is also alive and well within creative fields despite its illegality.
Yes the world is full of gatekeepers, if you want an internship you've bought into that system.
Good luck.