I always figured the hat had a secret condition in it to try and be kind of even. There are lots of students that the hat thinks could go to multiple houses. Doesn’t need to be perfectly divided but something like a mercy system in a gacha game.
Remember though that many families have the option to homeschool as to total numbers of eligible students as well as attending an entirely different school location. Which, of course, would skew numbers incoming.
I think it would be a statistical anomaly if all or none of the students fit the criteria for any of the houses. So probably the hat has to try and distribute the students fairly.
I mean correct me if I am wrong. Like the American school Ilvermorny the statues pick the students and more than one can pick. If the houses are uneven the same as Harry could’ve been sorted into multiple houses maybe the hat gives the student a choice. Tells them what values the different houses hold for the student and see if they are willing to accept a different house.
Just out of interest, how many students are there in one year at Hogwarts. In the books two houses share a class, so it can't be too big I would imagine. I initially thought it was just ten - five witches and five wizards, based on the original forty list that JK Rowling created - which would mean a class size of twenty. (Ten Gryffindors and Ten Slytherins for Potions for example). This would also mean each house would only need fourteen dormitories to house a total of 70 students per house, and 280 in the entire castle This would fit in with all of them travelling on the Hogwarts express, and also the length of the sorting. Forty new students is a reasonable amount in order for everyone to get sorted, have the feast and have a decent night's sleep before classes begin the next day It would also be more convenient for Head's of Houses too as they would only have to look after seventy students each