They were building towards "mad queen," but the way she broke with reality was way outside the scope of what they were driving towards and what was realistic.
They built to this through various events:
-Crucifying a hundred and something great masters. This was supposed to be justice for the slaves who were crucified, but she didn't carefully investigate to discover which ones were responsible. This isn't something that really makes her unsympathetic to audiences, because slave masters aren't sympathetic. But it's still a move in the tyrant direction--blindly committing acts of violence in the name of justice.
-Executing someone without a trial for the crime of executing someone without a trial. The sheer nature of "the rules of justice don't apply to me" is rather staggering.
-She has to be talked down several times from simply flying to King's Landing and burning her way to victory
-She burns the Tarlys because they won't submit to her as their rightful ruler, despite the fact that they've made vows to others. They've surrendered...they simply aren't willing to recognize her as their rightful ruler and there's no particular reason that they should. There's nothing normal about burning people to death in that scenario--they're prisoners of war, something that's happened many times in the story. An easy example is when Robb Stark took Jaime Lannister prisoner. Jaime didn't submit to Robb as his rightful ruler and Robb didn't simply execute him (or the other, less valuable prisoners).
-Less about violent madness, but still part of her progression towards being a tyrant of the type she supposedly hates: her entire claim revolves around who she is and who her father was. Yet, when someone comes along who's claim is superior to her own by her own rules--suddenly she feels threatened because...it was never really about claims and rules. She wants the throne.
Much of her problematic (to understate it) behavior is whitewashed by the fact that the people she's frying or murdering aren't particularly sympathetic or friendly people (Dickon Tarly possibly being the exception). So even though she's manifesting pretty terrible behavior, because she's killing people the audience doesn't like, she still seems like a protagonist within the normal bounds.
The precise turn of her madness seemed set properly when she said, "True mercy is making sure future generations are never held hostage by a tyrant"--i.e. that she's willing to burn up innocent people for the greater good. That turn of madness would have been within her character and been a logical conclusion to her progression. Instead we got, completely out of the blue, essentially "True mercy is just randomly killing innocent people because I'm angry about my life circumstances."
So, yes, the show has been setting up her "madness" for a while, but they botched the end point, giving her a madness that makes no sense.