Four possible explanations for Mario and one for Zelda games. As for others... well, I guess the player's weapons are actually a form of Zat'nik'tel. : P
Mario
1.) It's an early warning system
The rising smoke from the deceased troops warns Bowser to set up the traps in the next castle. I mean, who builds a castle with no floor?! That's definitely some sort of defense mode that gets activated on Mario's approach.
2.) The enemies are illusions/magically constructed
Goombas are actually mushroom kingdom residents that didn't have the good sense to turn themselves into blocks before Bowser cursed everybody (well, at least in the original). Perhaps their vanishing in a puff signals an end to the spell, and they wake up back in their homes back to normal. The Paper Mario series sort of contradicts this, but it's a thought.
3.) They're kicked into the foreground
When Mario dies he falls off the level. Where do all his extra bodies go? You know, the ones that died before the 1UpShroom cloned him? They're piled up under the screen, with all the goombas and koopa troopas he's been slaying the whole time. This theory actually gets MORE plausible when you consider the 3D titles. Have you ever noticed that EVERY area in the mushroom kingdom hovers over an abyss? That's where they put all of the bodies. (This option may have been inspired by a weird PS3 game called Catherine).
4.) They're teleported to the Underwhere
This is where you go when all your games be over. Super Paper Mario supports this, as the afterlife is a physical place that can be reached from Flipside.
Zelda
1.) GANNON-BANNED TO THE EVIL JAR
Enough said.
Something that's always bothered me about video games and particularly RPGs is the fact that the world is coming to an end, but all of the magic McGuffins you need to stop it are conveniently located within the same country or--if not--tucked tidily in the center of some ancient ruin. The magic nya-nya is never accidentally buried in somebody's backyard or dropped in the ocean or something.