Not just the school aspect.
The idea of a young person who is mistreated in their day to day life escaping to a fanciful world where the normal rules don’t apply and they are accepted and loved by their peers. A world they enjoy and like, that sounds like a place they could belong.
Kids and even Adults want that, they want to put themselves into that character, they want to be that character. Look at the grown adults you see wearing “Still waiting for my letter from Hogwarts” t-shirts.
That is the appeal of Harry Potter. It’s escapism from real or imagined hardships in the reader’s day to day life into a world they WANT to be part of.
My wife suffered horrendous abuse growing up and Harry Potter was one of her few escapes, she wrote to J.K. Rowling to thank her for her means of escaping from the abuse, albeit mentally (although for various well documented reasons she now feels a bit differently about Rowling)
That sounds a little bit like the Lazarus Project, a BBC TV Show.