I don't think the PCs should be confident that they can beat every encounter, but I don't really design them with the thought in mind "Hah! This should kill them." I'm more apt to think "It should be interesting to see how they deal with this."
I have only been a part of one TPK that I can recall as player, and that was because the DM had ignored the agreed-upon rules for a rotating DM campaign in 3e. (There were probably others from 1e days, but 1st level TPKs didn't count back then, IMO.)
I have only presided over a few TPKs as a DM. The most recent was a rather odd one, where all four party members trotted into a room with a psychic/magical trap, that they knew about....and all failed their Wisdom saves, even the ones with re-rolls and re-tries and advantage, etc. The weird part is that they went in one at a time, and after watching all his comrades succumb to the trap....the cleric just hopped right in behind them... Go figure. Usually, the TPKs come after the party has completely ignored my hints, warnings, and advice or just simply throws caution to the wind against even their previous experience in the campaign.
As others have noted, TPKs seem very random to me. I've never had one happen at an intentionally dramatically climactic moment. Its an odd way to end a campaign.