A few years ago, I ran an encounter in which I planned for the PCs to be captured with two different groups. The druid in the first group managed to basically solo the whole thing after all the other PCs were incapacitated.
So I just went with it from there. It wasn't totally critical to the plot that they were captured, and I was able to adapt what I had planned next to deal with this. (I think the druid actually just managed to escape and put up enough of a fight that the NPCs decided he wasn't worth pursuing. I forget.)
When I ran the same encounter with the other group, the PCs were all dropped with in a couple of rounds with few or no NPC casualties. (They didn't have a druid.
)
I agree that it is important to make it not feel like a railroad. In my encounter, I had one NPC wizard that was equal leveled (or a bit below... I forget) with the PCs, and he was accompanied by several lower level "mooks" (orc rogue 1/barbarian 1s duel-wielding saps) (the PCs were about level 5-6 IIRC). The mooks by themselves would have not been that dangerous, but in an ambush situation with the wizard using spells to incapacitate and hinder the PCs, they were quite dangerous. The "fluff" on this NPC group was that they were slavers, so it made sense for them to be taking prisoners and using non-lethal tactics instead of trying to kill.
So I'd advise you to:
1) Make it so that they actually have a chance (even if it is a slim one).
2) Make a plan about how to run the rest of the adventure if they actually
win.
3) Have a reasonable explanation about why the NPCs would want to use non-lethal methods, instead of just killing them.
Hmm... having a trapped room/hallway/etc where the door closes and a bunch of poison "knockout" gas floods in might be fun. You could also throw in some monsters that are immune to it and that use non-lethal methods, like skeletons equipped with saps and ordered not to kill them, etc. If the treacherous NPC is also knocked out, they PCs might not even know he's a traitor even after they wake up and find themselves captured. He could still be used to further betray them, getting them to confide information in him, etc.