If the answer is, so the players can show off how clever they are in playing their PCs and beating the GM's challenges, then why would you tell the players what to do? That defeats the whole purpose.
If the answer is different, though - maybe it's something like "To find out together what these PCs are about, what makes them tick, how their future will unfold as heroes" - then you need to ask yourself, as GM, What is the point of sticking to your guns and resolving a situation like the undead or elemental fight in a rigid way, as if there's only one right answer, and if the PCs suffer a TPK then c'est la vie?
I don't think anyone has suggested that "failure = TPK". I think the only failure that = TPK tends to be players who run characters who will walk through a meat grinder because the game, to them, is just combat, and the prospect they could lose is unfathomable. This trap sounds quite similar to the Undead situation in that both allow the PC,s to retreat with limited or no consequences. They have the option of stepping back to lick their wounds and reconsider their options.
I always liked the old Villains &Vigilantes modules' approach of specifying what happens if the players lose this combat. Having a sense of what happens if the PC's fail, as well as if they succeed, means the GM is not at a loss when it happens, and it becomes clear that it's not only OK to fail (ie that's not "TPK - scrap campaign and make new characters"), but that failure can lead to a game session at least as fun as success will. It also can jar "those players" out of the worldview that the PC's can never fail so there is some acceptance that, sometimes, they are just overmatched, and that this, too, will advance, rather than end, the game.
This is what games like Burning Wheel, Marvel Heroic RP and now 13th Age talk about as "fail forward" ie when you resolve a situation, the PCs might succeed or might fail, but if they fail the game (and the story of the PCs) doesn't come to an end. Instead, things go on but with the PCs at some sort of disadvantage or having paid some sort of price.
As noted above, this is hardly some revolutionary indie game concept never considered before. It's Drama 101.
This sort of adjudication requires flexibility as a GM, coming up with interesting ideas for failure on the spot as the players tackle the situation in whatever way they think makes sense, and you as GM adjudicate those actions and tell them what happens.
Considering other approaches is the same. In fact, it's quite possible to plot out an adventure with "if the heroes fail here" planning, so that you don't need to do a lot of thinking on your feet to adjudicate those results.
So, for instance, if the PCs deplete their resources fighting the undead or the elementals you don't frame the next fight as one that will kill them - but you frame things so that other consequences of that resource depletion become clear to the players (so, for instance, in your example they can't stop the village being burned down).
Sure - the village gets burned down; the Gate gets opened; the prisoners get released; the Bad Guy gets the magic artifact he was seeking; whatever. And the game goes on. We must rebuild the village/stop the army that's been released; close the gate/defeat whatever came through; recapture/slay the former prisoners; stop the Bad Guy before he can use that artifact for his nefarious ends/whatever.
In a good game, the players generally won't know whether they were "meant" to succeed or fail. Some years back, I had a player survey the field of combat, look at the group and say "Guys, I think this is one of those battles we just weren't meant to win". Actually, it was an encounter I had expected to be challenging but that they would win, but things had gone poorly for them for a variety of reasons. They didn't need to know that. The Bad Guys had goals not involving the PC's, so having won, they went about their business. The PC's, meanwhile, spent a lot of time and effort planning out the "inevitable rematch". The only thing that made that rematch "inevitable" was that I had to write it in after seeing how much they were looking forward to it. And that later rematch was a great session.
In a GREAT game, the GM should seldom, if ever, have a preconceived notion of what the players are "meant" to succeed at, at least when looking at significant challenges.
Now this can be harder to do in D&D, which has very specific and highly silo-ed mechancial resources, rather than in a more abstract system where spending resource (eg Fate Points) on fight A leaves you without enough Fate Points to achieve goal B (like stopping the village burning down).
First and foremost, getting out of the mentality that every battle is "one side wins and the other dies" is the first step. Methodically slitting the throats of the fallen isn't the expectation I have for heroes, nor does it tend to be the source material's approach. If it was, Luke Skywalker would have been Wampa Chow, James Bond would have been executed in his first outing and Batman's head would be on the Joker's den wall long ago. Once we recognize "lose" and "die" are not synonymous, a world of possibilities open up.
The heroes can't stop the village being burned down because the spells and HP they needed to defeat the enemy behind that arcane ward were used up fighting the elementals, or just because they took so long to figure it out that the enemy could marshal his forces so they moved en masse, and could not be picked off by a rag tag group of adventurers while they were still planning the raid. Or, perhaps, there was no rush to get into that area, nothing was going on there anyway. If that door has been sealed for 500 years, three more days should not make that much difference, should they?
Yet a third reason for playing D&D is for the players to experience the thrill of "being there", and of playing through the GM's story. For those players, maybe telling them "You recognise the runes as Arcane. They were probably put there by the Archmage" or "You can tell this trap isn't a dwarven one" would do the job. Because that helps those players get the feel of being there, immersed in the situation of their PC. It prioritises "being the PC" over making choices for the PC.
I'd call these "trivial difficulty". Anyone who can read Dwarven knows the runes aren't Dwarven, and anyone with any arcane knowledge (a rank, a spellbook or the ability to read a scroll) can see they are Arcane.