It was a combination of actually being good for the first couple of books, marketing push from Scholastic after it’s breakthrough success in the UK, and being able to connect to kids in ways other books weren’t at the time.
Harry Potter was never pushed in schools and so we read older classic and Caldecott Medal books. Here comes a story that’s about school, the thing you’re stuck in, but with wizards. Every kid would rather be casting spells than doing regular school work so the concept alone got the kids hooked.
This was also around the time of the Pokémon craze and I wouldn’t be surprised if Scholastic was hoping for something similar with Harry Potter.