I disagree they are badly written. They are so immersive, the world is just so exciting and cool. It really is a magical world. I can imagine myself there, they are completely believable - I am still waiting on my letter 
For me as a child they were the first books I read that didn't feel they were written for a child. They weren't patronising or silly, they might not be amazing prose but they are easy to read without being childish, they really spark the imagination. The characters are perfect, they are real characters who are different, and fulfill a role but without being silly caricatures. They are well developed characters.
The story also has a bit of everything. It's not just malory towers with magic. You've got the boarding school, no adults, you've also got the orphaned child maltreatment part. Bit of mischief and breaking the rules, bit of humour. Harry is not a character where things always go well or always go badly. Voledmeort is a good baddie, he is properly evil but without incessant
Personally I think she strikes the perfect balance between real and magic. The perfect balance of badness of her bad characters. The perfect balance between adult and child, dark and humour etc. And hence they appeal to everyone. I read a lot as a child, and maybe things like Phillip pullman are better books, but they are also harder to read and I don't think have stayed with me in the same way harry potter did. I have no desire to live in that world, whilst everyone wants to go to hogarth!