Being in an AP class doesn't mean you're smarter, it means you're better behaved.
When I first attended my high school I tested into something called the SUMMIT program. This meant I was a "smart kid". In other words, I would get special classes and teachers.
It turns out, these classes weren't that hard, nor that much different. The only difference was the students were better behaved.
Grades are a measure of how behaved a kid is, not how smart they are. Think about it.
If a class clown distracts the classroom and disrespects the teacher, what will happen? Anytime the teacher sits down to grade papers, and the class clown's name passes by, they'll naturally be more critical of their work. The class clown gets worse grades and in turn and doesn't attend "smart kid classes".
Grades are a filtering system.
If a well-behaved kid's paper passes by, a small smile will emerge from the teacher, and they'll be more lenient with grading.
Obviously, this isn't the case all the time. But, it's definitely an overlooked factor. Think about it another way. If the class clown acts up in all their classes, then all those teachers will grade more critically. This in turn makes that student's GPA drop. Hard classes are for behaved kids. Easy classes are for misbehaved kids.
Grades are popularity points. Cronyism exists in the classroom too. And biases happen whether you like them to or not. Bad kids are not dumb kids. (more on that in a full-length article coming soon to my Medium)