There are two important things about twists to be taken into account.
One of them is foreshadowing. Events that seem meaningful but their full meaning in unclear until the twist is revealed - and then everything falls into place. Foreshadowing ensures that the twist does not come out of the blue. When it happens, players think "Why haven't we realized it earlier? It should be obvious from the facts we knew!".
And maybe they do realize it earlier. In this case, the GM should accept it, without trying to change things behind the scenes and take the well deserved success from players. A twist well foreshadowed is like a good detective story - fun whether the reader deduces the solution or not (getting the "I should have noticed that" moment).
The other aspect is how the twist fits the social contract and metagame conventions of the campaign. For example, in most games I run, the story is strongly player-driven. When I create NPCs for players to encounter, I make no assumptions on whether players will like them or not, if players will trust them and what will come of their interactions. And players know about it. NPCs have their beliefs and motivations and it's not that rare that a genuinely moral person is opposed to PCs for some reason.
But in a quest-driven game, there is a metagame convention that quests are accepted. If players become distrusting and refuse to accept quests (or haggle too much on rewards, or demand explanations why the patron does not handle the matter themselves, or ...), the game grinds to halt. The group, for metagame reasons (fun play) ignores this kind of concerns and skips to the quest itself. So if a patron betrays the party, it's not only an NPC abusing PCs' trust. It's also the GM abusing the social contract.
+1
This advice is perfect. It's what I wanted to say but you already said it better.