I think a big part is that many (most?) children find school – i.e. lectures, textbooks, homework exercises, exams – unmotivating/boring at best, and often extremely stressful/frightening, which means that they aren’t fully focused on it and can easily miss important details. Beyond that, schools often fail to provide meaningful feedback or support when people suffer serious misconceptions or are missing fundamental prerequisite knowledge/skills, which makes it easy for students to fall behind and have great difficulty recovering. Someone who spends the exact same amount of time on academic work but for whatever reason (external help outside school, internal motivation, some insightful introspection, ...) manages to pay closer attention, stay more relaxed, think about things ahead of where the class is expected to be, connect new learning to material learned before and build a better-connected mental map, etc. can end up pulling far ahead.
A whole lot of this has to do with level of preparation before ever arriving at school. Some kids read with their parents for hours every day from age 1–5+, learn to play a variety of strategic games (and games involving basic arithmetic practice), build structures or mechanisms or electronics, practice making art, work through books of logic puzzles, etc. Other kids are left alone and bored without learning materials at a reasonable level, plonked down in front of developmentally inappropriate or just badly produced TV, or handed over to unthoughtful video games.
Then consider how many kids and parents have serious problems at home, with confrontational or even abusive relationships. Pile on work stress, financial stress, poor diet or even hunger, poor sleep, environmental toxins, illness, etc.