A masterful story is a lot of things. It carries plot, characterisation, tension, meaning, and absolutely, unequivocally does not make its audience go, “What? Where the fuck did that come from?”
The WTF reaction from your audience is one of the fastest ways to get people to hate your story. There’s a reason people froth at the mouth when discussing the Deus ex Machina trope. People hate feeling left out of the loop.
The loop, in this case, being the Setup/Payoff cycle.