And this is brilliant. Because it demonstrates that racism isn’t only present in clearly malicious and evil people, in the Malfoys and Blacks - it’s also there in warm, kind, funny people who just happened to learn some pretty toxic things growing up in a pretty toxic society. And they can unlearn them too, with some time and effort. Ron eventually accepts Hagrid’s parentage, lets Lupin bandage his leg and in the final battle, he worries about the safety of the house elves.
Some people are prejudiced because they are evil, and some people are prejudiced because they don’t know better yet. And those people can learn better, and become better people. And that’s an important lesson. The lesson taught about discrimination shouldn’t be “only evil people do it”, because then all readers will assume it doesn’t apply to them. Instead old JK teaches us “you too are probably doing it, and you should do stop ASAP”.