I think the trick to a good story twist, is set up, and pay off.
You need to give the characters enough motivation to justify the twist. This is why the final season of Game of Thrones fell flat in my opinion. There is nothing wrong with having Dany become the villain, but it needs to be properly set up and motivated. Earlier seasons of Game of Thrones were fantastic because every twist felt like a logical outcome of earlier events in the story. The best example of this is perhaps the battle between the Mountain and the Viper. We know that prince Oberyn is obsessed with getting revenge and is very sure of himself, and we know that this trial by combat is Tyrion's only escape from death. So Oberyn has got to win this fight, right? And for the first part of the fight, it seems that is exactly what will happen, until it suddenly all goes horribly wrong. However, as surprising as Oberyn's death is, it is set up ahead of time. We see him showboating and being way too sure of his victory, while we also know how strong and dangerous the Mountain is.
But then there's the pay off; it has to lead to a satisfying plot development. Oberyn's death raises the stakes and puts Tyrion in an even more hopeless situation that before.
Likewise, the Red Wedding is probably one of Game of Thrones' best most shocking twists. It is also the catalyst for all the exciting events that follow. Robb Stark has to lose the war in order for the story to continue. This was The Last Jedi's greatest failing in my opinion. Throwing out twists just for the sake of subverting expectations is no good. The plot can't be left stranded. If you set up expectations, and then surprise the audience by having no satisfying conclusion, that is just poor story telling.
I try to keep these ideas in mind when writing story for my D&D campaigns. I try to set up expectations and red herrings for my players, and then surpise them with something exciting that they didn't see coming, and yet is a logical outcome of the plot that pushes the story in an exciting new direction. This is why I am not going to kill off my big villain early (like in TLJ), because then where does the story go from there? I don't want to surprise my players with an anti-climax that doesn't lead anywhere.