That act was not a matter of sense. How could it be?
It's pure rage and desperation. She achieved her goals. Her story came to an end. Her conquest was successful, her "destiny" fulfilled. And suddenly, everything that helped her cope with all the pain she has suffered vanished.
Hence the "mad" label being used to describe the act, which I don't agree makes a narrative sense with her characterization since coming to Westeros. Ever since coming to Westeros, she was the most rational character in the show with her most trusted allies betraying her for absolutely no reason before she even did anything dramatically bad while the others died and Grey Worm didn't even killed Jon and Tyrion in retaliation.
The problem with that act for me is that it doesn't really work by itself but more as a justification of everyone else's behaviors but after said behaviors happened. It's either an unexpected decision or a realistic possibility but it cannot be both.