Tl;Dr - there are 280 students in Hogwarts, but the castle is so big that it feels like there should be more. This is because the castle grows over time, and at one point was servicing the British empire so had a much larger population of students and when the British empire collapsed it's number of students shrank leaving it with a castle larger than necessary to support a student population of 300.
So to begin with, despite JK saying that there are 1000 students at Hogwarts, I believe that there are actually closer to 300 for the following reasons (skip this bit if you're willing to just take my word for it, though I can't say I blame you if you don't):
1 - year size: given every house appears to have 2 dorms (a boys' and girls' dorm) each consisting of 5 students, it follows that every house has 10 students and as there are 4 houses there are 40 students per year and therefore 280 students in Hogwarts
2 - class sizes: there are 20 students in an average 1990s Britain class and every class consists of two houses, i.e. half the year, meaning that every year would be 40 people, fitting with point 1. Whilst it could be said that those two houses might not be the entirety of their house implying a larger year size, I doubt this is the case on the grounds that with 2 classes at a time per year and 7 years, that's 14 classes at a time, and there are 14 teachers at Hogwarts.
If there were more students and thus more classes then you wouldn't have enough teachers for all of them, unless the teachers used time turners, which is unreasonable as it makes already ancient teachers like Dumbledore and McGonagall even older biologically - at least a few years for every decade of teaching they've done.
3 - UK wizarding population: JK Rowling has said (somewhere I couldn't find exactly where) that the Wizarding population of the UK is 3000 wizards and witches. If Hogwarts had 1000 students in it then 1/3 of the UK's wizarding population would be in education at a given time, a completely unreasonable suggestion.
Even if they had the population pyramid of a preindustrial society as has been suggested it still wouldn't check out as the main difference between industrial and preindustrial societies is in the 0-10 age group, and there's not such a huge difference in the 10-20 age group, definitely not enough to account for a third of the population in school.
Meanwhile having just under 10% of your population in school definitely does check out and matches the stats for 1990s UK fairly well.
But if Hogwarts has a population of ~300 students and teachers, why is the castle so big? Considering that there are around 4 or 5 times the rooms necessary to teach 300 people surely that can't be right (this website has a good in depth look at the Hogwarts castle layout? Well this is where we need to crack open Hogwarts a history and talk about how Hogwarts has grown.
Hogwarts was created by its founders over 1000 years ago in tenth century Britain. This was during the dark ages, long after the Romans had left Britain castles were only just becoming a thing in France and the most sophisticated castles in Europe were essentially a wooden fort on top of a mound surrounded by a ditch and wooden wall (Norman motte and bailey). And as this is the 10th century the Normans haven't even invaded yet so not even that technology has spread to the British isles. Furthermore stone castles wouldn't emerge for another few centuries.
The point is that it's highly unlikely that in the tenth century the Hogwarts founders built a huge sophisticated stone castle in the Scottish Highlands. Not because the couldn't - I've no doubt if they knew how they would possess the magical capability to make them - but because castles of that size, scale, sophistication and material hadn't even been invented yet, and this is before the wizarding world went underground so we can't just assume they had the technology and were just hiding it.
A far more likely explanation is that Hogwarts grew over time and was constantly updated. Hogwarts wasn't always a massive stone castle, it was originally a much simpler building that got slowly updated over time. This explains why it's such a messy Hodge podge of rooms towers and corridors with so many secret rooms and forgotten passageways. Also this is why they have the moving staircases - they need to move to access the bits of the building that were added on later instead of building entirely new staircases.
There are two other main pieces of evidence for this point: first, when Rowena Ravenclaw helped design Hogwarts, she helped create an ever changing floor plan. Whilst this could be a reference to the moving staircases, I find it far more likely that this is referencing the fact that Hogwarts is constantly growing and updating.
Second, the wizarding population of the UK is going to have changed over time. Given that in the 11th century England had around 3% its current population, that means that if the wizarding population of the UK has changed in step with the overall population of the UK, there were only 9 students at Hogwarts to begin with, or 30 if you take the 1000 student figure. Given such a small school size it's incredibly unlikely that the founding 4 would build an massive castle just to house less than a dozen students. So Hogwarts has to have grown over time.
Ok so back to why that's relevant. Hogwarts grows to meet the needs of the school and house more students when necessary. How is this relevant to the fact that it has so many empty rooms then? Two words: British empire. Hogwarts didn't always just serve the British isles. Hogwarts once had to serve the needs of the entire British empire, which had a population 8 times that of modern Britain.
If we again take the wizarding population of the UK to be in line with that of the rest of the country, that's 8 times the Wizarding children to be educated. Now we can assume that not all the wizarding children in the British empire will have attended Hogwarts. Many wouldn't have access to the education (e.g. wizards from poor families in India and Africa). Some will have gone to other schools closer by (e.g. Canadians going to Ilvermory). So we can cut that number in half, meaning Hogwarts would be serving 4 times the students it is today.
And just like magic (or rather just like arithmancy) the numbers fall into place: 4 times the students, 4 times the rooms. And when the British empire collapsed, this left Hogwarts with a load of spare empty rooms meaning - they had 4 times the rooms necessary, which matches with what we saw earlier.