It's dependent on several factors - teachers, peers and in general how other children view bright pupils. Without the supporting environment, a bright pupil will become average.
In my experience, I went to both a mixed comprehensive and a selective grammar school - stark difference between the two.
Mixed comprehensive, the standards were low, misbehaviour and fighting throughout the school day that teachers couldn't get through the syllabus. I had to do a lot of studying at home simply because it wasn't covered in class. Mock exams/tests, I'd be deemed as "good enough" if I got an A rather than A*, and teachers were too busy trying to move the D graders to C's - so that the stats would look good. Lots of bullying because if I did homework that meant I didn't have a life/was a virgin/no friends etc etc. No ambition, everyone wanted to be footballers or hairdressers (nothing wrong with that but in a year group of 180 kids, you would expect at least some to want to go to uni). Plenty of kids taking drama/PE/food tech/media and ready to drop the more academic subjects as soon as possible.
I studied my butt off and got into a grammar school with a crazy difference.
There was a studious atmosphere, the kids studied, doing homework wasn't a 'sad' thing to do for people who had no friends, there was ambition to be doctors, bankers, business owners, architects, finance, tech. Plenty of girls studying STEM subjects. It pushed me to better myself.