In the realm of the show, it came out of the blue. What she did made zero sense for Dany on the show. It is nothing that has ever been hinted at her doing.
I don't know... Dany had a streak where she very often got caught up in being self righteously vengeful and it was usually ameliorated by the other people in her circles that advised a different course of action. We did see in Essos her actions which she saw as justice, many a times brutally enforced, came to bite her at a later date in some fashion. At the point where the attack on King's Landing occurs she's bereft of any of the influences that would have had any affect upon her mind or emotions. Ser Baristan, Jorah, Misande... All dead. She had lost all faith in Tyrion and was, in a way rightly, starting to see treason all around her.
That is not an excuse for the what they did on the show or how it played out on my part. The entire time she was laying waste to the civilians I kept saying out loud as I watched... "But... WHY?" It was as so many have said, rather rushed in terms of the evolution of the character. That said, I did a podcast a few years back on GoT and my friend Anna was on. She was a fan of both the books and the show. I had at the time a pretty conventional view of Jon and Dany as the most traditionally "heroic" characters on the show, thinking they were both simply going to stay in the type of roles as more or less "good guys" in comparison to everyone else. Sure, they'd have set backs or have to make tough calls but I assumed they both were destined to be honorable protagonists for the most part.
Anna disagreed and laid out that for Dany there were seeds there wherein she could easily slide down a road that would make her a mix of her father the Mad King and Aegon The Conqueror. That she could be blinded by her self righteousness to condone any sort of terrible action. Sure, we might think that Tyrion's spiel to Jon was ham fisted in a way but I think that, while the change was rushed, the essential take away is valid. Unmoored from advice that would tamp down these tendencies, feeling threatened by the truth of Jon's heritage, and on and on, this side finally broke free in an orgiastic violent outbreak.
Again... It was HELLA rushed. It needed a lot of time to percolate to make us believe it's legitimacy as a turn for her and for us to feel the tragedy of this fall from our collective graces... But I do see now that this potential was always there and under the surface but just didn't want to because as Tyrion put it, the people that were in her sights were usually morally objectionable and it was easy to root for her. But if we look back, bloody vengeance was never that far from her mind and even the mere threat of it before she was capable of delivering on the threat was something she pulled like a .45 out of her metaphorical holster time and again, like when she was at the gates of Qarth, warning that she would not forget if they left her and her people to die. She swore then that should she live despite their abandonment of her that she would burn that city to the ground. She had said that those that would not accept her rule could live in the new world she was going to create or die in their old one. She was always on this precipice.
Now again... How they got to that point where she went over the edge was not as earned as it could have, should have been. But the set up, the frame to base such an evolution off of I think was always there.