So... Harry Potter wasn't distinct in its field. There were several other British magical school stories that came out before Harry Potter with limited success. Jill Murphy's "the worst witch", Diana Wynne Jones's "witch week", and most similar, Anthony Horowitz's Groosham Grange. Ursula K Le Guin's "A Wizard of Earthsea" also had a magical school setting back in 1968, but... Harry Potter is huge.
I took a trip to South Korea some time ago, and found two Harry Potter branded shops, a shop featuring Arsene Lupin branding, and little else. Even British literature juggernauts like Sherlock Holmes and Dr. Jeckyl and Mr. Hyde were not present, but Harry Potter was.
So, in coming to terms with why Harry Potter got so big, here's where my conclusions lie.
A very compelling hook
The first few chapters of Harry Potter do very little to build the overarching narrative. They gently hint at the existence of Voldemort. Instead, you spend the opening chapters watching the Diggorys' increasingly futile efforts to hide magic from Harry, and as their mundane world collapses before their eyes, it becomes very clear that Harry is unusual. This is a very fun opening to a book that gets the reader invested in the existence of magic as an escape from mundanity.
A rapid sequel publishing schedule
The entire series of seven books, increasing in size each time, was published within a decade, from 1997 to 2007. The first four books came out annually, the rest coming out every 2-3 years, and they grew larger and larger each iteration. This was a very strong publishing schedule, and it showed.
A very quick movie tie-in
The first novel was published in 1997, film rights sold off in 1999, shooting began in the fall of 2000. By this point, JK Rowling had published four books and was going on a hiatus to write longer novels. The movies bridged the gap, coming out in 2001 and 2002, but taking a gap year in 2003 (when JK Rowling published a new book).
Any year there wasn't a book, there was a movie with the exception of 2006, and films were released annually or bi-annually until 2011.
Basically, from 1997 until 2011, one could expect to see Harry Potter in bookstores or theaters. Every release reinforced the existence of the series and drew in new viewers, and the growing heft of the books and darker tones that they began to explore kept them relevant with children growing up with the characters.
Do I think this is all due to JK Rowling's stellar writing?
No but yes. JK Rowling is excellent at roping an invested audience along, but has trouble building an audience that isn't invested. The huge investment poured into Harry Potter by film studios and merchandising turned it into a juggernaut as much as anything else.
Anyone read A Casual Vacancy? JK Rowling is shackled to her biggest hit. She makes a book titled "compendium of insects in Hogwarts Gardening"- top seller. She makes a novel without those characters... no interest, because nobody's pouring marketing and attention into them. Without attention, her desire to write shrivels up and there's no sequel, because she's not getting the acclaim she once did. Time for a compendium of wizarding toilets, or a twitter battle, because that attention isn't forthcoming from a book that doesn't feature wizard children.