I think you have to approach this from a slightly meta point of view.
We're all familiar with Chekhov's gun - that 'every element in a narrative is to be irreplacable'. So assuming you're following this principle, and doing it well, by the time your readers reach the stage where the victim is being rescued from the dungeon they're quite likely to be thinking 'so, what makes this character irreplacable?'
If the character does nothing that couldn't be cut prior to the betrayal, then the reader is not going to be surprised. If the character does very little that couldn't be cut prior to the betrayal, then the reader is going to be wondering why this dead weight is being dragged around and still not be very surprised. You need to think of a reason why the character is being rescued that is both plausible to the in-universe protagonists, to maintain suspension of disbelief, but is also plausible to the reader based on the literary conventions of whatever genre you're writing in, to lead said reader down a blind alley. To that end I'd suggest looking few a few books from authors you want to emulate and seeing how they introduce supporting characters, and what kind of roles they have them fill. Then take this and subvert it - the character fills this role, the reader thinks they know what's going on, and then pow, betrayal!
As an aside, if you do this really well, then I can imagine it may end up working against you. A truely surprising betrayal will by definition mess with readers' expectations. And if everything else so far has been lampshaded, that can be jarring. Depending on how the rest of the story is playing out and what kind of conventions you're following there can be nothing more satifying than introducing a character who is trusted by the protagonists, but the reader can tell is shady. The tension then builds from how and when the betrayal happens - the reader get a 'I knew it!' payoff, and you can still surprise them by revealing the betrayer's motives are not quite what they expected.