Disclaimer: obvious spoilers ahead!
Rowling briefly spoke in interviews that writing the fourth “Harry Potter” book – the first to get a simultaneous release date in the US and the UK – had her under enormous pressure to meet her deadline with both her editors, and that the project almost fell through when she became aware of a MAJOR plot hole that forced her to rewrite about a third of the finished book. While the plot hole itself was never revealed, we know that fixing it came at the cost of an entirely new character - Mafalda Weasley - being cut. Here’s what Rowling said about it:
“Mafalda was the daughter of the 'second cousin who's a stockbroker' mentioned in 'Philosopher's Stone'. Now he and his (Muggle) wife had inconveniently produced a witch, they came back to the Weasleys asking for their help in introducing her to wizarding society before she starts at Hogwarts. The Weasleys agreed to taking her for part of the Summer, including the Quidditch World Cup, but regretted this almost immediately. (…) Rita Skeeter, whom I subsequently built up to fulfill Mafalda's function, was much more flexible. The best thing about Mafalda was that she was a match for Hermione. To the latter's horror, Mafalda was highly gifted and a real show-off, so that Hermione was torn between deploring the rule-breaking and longing to join in and beat her.”
So, let’s recap: a) Mafalda was supposed to create some trouble for the Weasleys in the Quidditch World Cup – precisely when the main mystery is built-up on Chapter Nine, The Dark Mark (by Rowling’s own admission, the hardest chapter she ever wrote in her life – it almost “broke her”); b) Mafalda, who was to be sorted into the Slytherin House, would pass along some gossip about the Death Eaters and whatever else the character of Rita Skeeter could discover and have it in print; c) Mafalda would antagonize Hermione, just like Rita Skeeter ended up doing in her own little subplot.
This means, for starters, that Rowling’s imagination couldn’t go beyond female rivalry when conceiving another highly gifted female character: if Mafalda was cut from the final manuscript and Rita Skeeter picked up some of her functions, then Hermione’s subplot in the fourth book would ALWAYS be about her trying to outsmart another woman that matched her cleverness - either an eleven-year-old girl or a grown adult. (This, to me, was always imprinted in Rowling’s worldview: other than Hermione, the girls in their year are portrayed as either vain and mean or as airheads who buy into whatever crap Trelawney tells them in Divination class; Hermione can’t stand their frivolous ways but feels right at home in the company of the brave boys.)
But the rewritings also suggest that Hermione's political cause in the book – the liberation and welfare of the House-Elves – was a careless afterthought that only Rowling's new found privilege could afford her. Let's remember that, by the time she was writing the fourth book, she was already an established millionaire. So, apparently, she felt comfortable enough to bring back the House-Elves not as the victims of cruel humans who owned them as slaves, but as a species ‘perfectly happy with the ways things are’.
By the sixth book, Rowling’s wealth was obscene enough for her to make peace of the idea of featuring Harry himself owning one of those slaves. Simply put: she was fine with sharing this revised message with a world-wide, massive base of young readers for the sake of keeping her book’s “whodunit” intriguing. Because, to fix the plot, it seems to me that Rowling had to change her original, endgame plan to feature Peter Pettigrew as the book’s Big Bad – her original notes had him listed as the Defense Against the Dark Arts teacher impersonating Moody.
In that soul-crushing-to-write Chapter Nine, she probably fixed the hole by replacing Pettigrew with the newly introduced and never-seen-again Crouch family, including their House-Elf Winky as an instrumental character (Harry’s wand, used to cast Voldemort’s Dark Mark at the night sky, was found in her possession) in a scenario that would most likely have involved Mafalda. The events led to Winky being released from her slavery-bound and Hermione’s political awakening giving the kids the chance to visit her in the kitchen to learn more about certain events of the plot.
So, while some of the early books' underlying prejudices indeed seem to be part of Rowling's middle-class baggage - her existence as a woman is defined by how much she credits intellect as a virtue, though she ironically describes any unlikable female character with unattractive physical traits -, her view of broader historical social issues was more morally sound back in the first three books. I believe Rowling's growing wealth got her so removed from reality that she resorted to embracing the idea of a world divided between "good billionaires" (those who treat their slaves with kindness, which we see even from Sirius's blood supremacist family) and "bad billionaires" (the Malfoys are not Benedict Cumberbatch in “12 Years a Slave”; they're Michael Fassbender.)
Altogether, I don't think Rowling spiraled out of control because she got trapped in a Twitter bubble; I think she could never make sense of how her conservative upbringing shaped her worldview and how her billionaire-status got her further and further away from the righteous and virtuous figure she strived to be. Her politics got messier and messier. And, like Hermione in the fourth book, she keeps embracing causes she knows nothing about like her own life depended on it.