@IamTomHanks makes a very good point. Any book from the Bible onwards will reflect the mores of the time it was written. Should we refuse to read `Jane Austen because in her books the only good future for a young woman is marriage? I love Louisa May Alcott despite the fact that they portray Irish people as feckless beggars or servants, somehow of a different class to other white people. Reading that as a 10 year old from an Irish family I knew it was wrong and that modern people didn't think that way.
One of things I loved and still love about Harry Potter is that the protagonists, young and old are all flawed. They can be lazy, slow, selfish, stupid even. They ignore advice and make mistakes. They judge one another. But just as the good aren't wholly good, most of the bad aren't wholly bad. That's so true and showing it is a rare thing in any fiction, let alone something aimed at children.
I think it's the mark of great novels that they are still read and appreciated for their strengths even after society changes radically. I don't know if HP will stand that test of time or whether it will go the way of the soupy romantic Pegs Paper type fiction of the 20s or Billy Bunter, dismissed as irrelevant, but at the moment I can enjoy it for what it is.