Hermione is the only character who’s even close to being on the right side of the slavery argument in HP, and even then she is happy to accept her friends owning slaves where it benefits her as long as the slave owners aren’t too cruel.
Slavery is as old as humanity. For literal millennia nobody thought twice about having slaves - across the globe and throughout all of history slaves have come from everywhere and been owned by everybody and for thousands of years everyone thought it was fine. Literally - slavery goes as far back as historical records - abolitionists crop up in the 18th century. That is a long time of no one doing anything about it.
Wizards are ass backwards in so many things, why on earth should it come as a surprise that they are ass backwards on slavery? even the nice ones? and it takes the person from outside that world to spot the problem. Because it's actually so much easier for Hermione, as an outsider looking in, to spot everything wrong with the wizarding system than it is for those born within it to see the problem.
We are not inherently morally superior to our ancestors because we know slavery is wrong. We just happen to have been born at a time after the system and the rules changed so get the benefit of those changes. We are born after the hard work is done and get to claim morality on that basis - but that's not really fair is it? The people with an actual claim on morality are those born in the system who looked at it and realised it was wrong and did something about it. They are the giants whose shoulders we are standing upon and in the wizarding world, Hermione is that giant.
Perfectly decent people will have told William Wilberforce to shut up and stop being so silly. Loving parents, hard workers, kind to everyone around them, generous to a fault ... who just happened born into an ancient system and were living busy and complicated and hard lives of their own and couldn't see that injustice was the very air they breathed. That's who the wizards who laugh at Hermione are - that's why Dumbledore implores kindness but hasn't got to freedom yet.
Sirius says in book four 'don't judge a man by how he treats his equals, but how he treats his inferiors' ... which is very wise and very noble, and completely hypocritical of him because of how he treats Kreacher. But that doesn't stop him being brave, or a loving and loyal friend ... it makes him a man with a blind spot for his own poor actions. Like literally every single person on the planet. Like all the other characters. It's what makes them compelling and stops them being total Mary Sues that no one cares about.
It's made perfectly clear that wizards are in the wrong when it comes to the treatment of magical creatures. Hermione states that she always said wizards would pay for their treatment of House Elves and draws a direct line to Sirius' death. The godfather of her best friend - and she wasn't afraid to blame him, in front of Harry, for the part he played in his own undoing. Harry looking at the fountain of magical cooperation thinks about how untrue it is and - essentially - what a load of bullshit it is. When Griphook talks about the injustices done to Goblins by wizards and asks who says anything about it? Hermione replies 'we do!' Griphook notes that Harry is an unusual wizard because he took the time to bury Dobby, and we absolutely know Harry was right to do it - so the implication is all other wizards are pretty shit.
The whole story is about these young wizards - particularly these outsiders - entering a stale, unjust, self satisfied and crumbling society and ushering in something better. You can't usher in a new and better world unless the old one was pretty shit. The treatment of House elves, the treatment of goblins and werewolves and the notion of blood purity is the setting of the old order which Harry and Hermione tear down. But they couldn't tear it down if it wasn't there in the first place.
And then people say it's problematic or racist to include these institutions and show them as an unseen, unthinking part of the fabric of society. FFS.
No - it's fucking story telling. The House elves are one tiny sub plot in a rich and textured world. The stories highlight the flawed system and the beginning of the attempt to change that system - there would have to be ten more books all the length of The OOTP and focused on nothing but the house elves in order to get them to a point where the problem is satisfactorily fixed. Britain outlawed slavery in 1833 - the events of the past week show it still isn't fixed yet. Not having an easy fix for a complex situation is not a sign of racism. Not everything has to be wrapped in a neat little bow and spoon fed to an audience by the end of a story - because stories are about life and life aint like that.