All books are written in the context of their time and Harry Potter was written starting in the early 1990s. I doubt anyone of us had ever heard of LGBTQ+ in 1997. Well, we'd heard of LGB and there was still a huge stigma.
The fact we're having this conversation is a sign of how far we've come for the better.
I always have it in my mind that JKR wrote the way she did to show that Hermione did deserve better and there was a moral in there that you shouldn't make your friends cry and emotionally abuse your wife. The whole series is full of skewed morals in a way. Harry did have some Slytherin in him after all.
I do remember reading CoS and crying when Lockhart said that he stole work from a witch because she had a 'heirlip'. A term which definitely WAS offensive in 1998. It has been changed now, and again I think it was written to show how repugnant Lockhart was as a character that he was so prejudice.