St Andrews isn't typical of most good universities though: It's in a town in a relatively wealthy part of the country with a population of about 15,000. The only sizeable place nearby is Dundee, half an hour away, with a population of 150,000. As a result, it has no 'catchment area' to speak of, so isn't subject to the same pressures as universities like Glasgow or Edinburgh which are in urban areas of 1.5m and 750,000 respectively.
Poorer students are much more likely to apply to close-by universities, mainly because they can stay at home. St Andrews, despite what one might think, isn't particularly fashionable as a study destination amongst Scottish applicants: I believe they received about 4,000 applications from Scotland- about one fifth the level of Glasgow. So, while Glasgow receives Scottish applications by the bucket-load based partly on location, it tends to be people who want to move to St Andrews that apply- this immediately provides a different demographic. Given that Glasgow University is in the affluent part of the city with expensive rents and well-off families but much of the surrounding 50 miles contains a large chunk of the poorest parts of Scotland (it also contains nearly half of Scotland's population), they don't even have to accept many applications in order to appear much better than St Andrews at social mobility. I don't think this has all that much to do with 'accepting the best' either. Actually, since only 3% of the surrounding area is privately educated in Glasgow, the case could be made that it is just as unrepresentative (20% of Glasgow University is privately educated) as anywhere else.
Secondly, the point has often been made that students who are the first in their families to go to university tend to not want to study Philosophy or History of Art, and as a result, a big chunk of the courses at Glasgow, Edinburgh, Aberdeen and St Andrews are not appealing to them. Computer Games technology, Tourism, events management and so on have been far more successful at recruiting those not traditionally drawn to higher education (unsurprising really), and thus, part of the selection bias pushes students down the road to newer universities offering non-traditional courses. There's also the issue of the students themselves not feeling like they'd 'fit-in'. Like the fact that students from certain schools tend to apply to the same universities, so too do students from different backgrounds not choose those universities for the same reason. I have heard numerous times students at a modern university saying the people at the older one in the same city are stuck up and not 'ordinary' people (by the same token, I've witnessed students here on TSR look down their nose at good universities because people like them don't tend to apply there, Liverpool being one example).
Finally, universities do have a duty to make sure they aren't closing doors unfairly to people who are good enough. The task is to work out whether they just don't want to go there (either before or after application), if there's an academic reason why the ancient universities don't do vocational subjects that they're unwilling to bend on, or if they really are at fault. The point has been made before that certain institutions with lots of well-off students have more polished rather than brighter kids. I've seen it myself first-hand. Student A might have AAB, but goes to a school where A*A*A*A* was the top grade, and is actually relatively poor by comparison to his or her peer group. Student B might have ABB, but was top in an inner city comprehensive and attends a different institution. The one with the better education might be easier to teach initially and know how to write good essays straight away, but there's a danger that by only looking at grades on paper, you miss out on the best as a result. This is where St Andrews has to be careful, not whether it takes 13 or 30 students next year.