- The cave is where the player is in the game. If we want the player to have access to a shopkeeper, we either have to put the shopkeeper right there, or else we have to build somewhere else for the shopkeeper to be, and building that somewhere else will probably be expensive (in terms of new art required, etc). Additionally, making the player go somewhere else just to find a shopkeeper probably doesn't make the game better; it just adds a bunch of backtracking, or requires that we create Scrolls of Town Portal or something. (If you were asking for an in-game-world reason to justify why a shopkeeper is in the cave, I'll point out that we're talking about "caves of doom", and so a realistic world with internally-consistent lore which will stand up to any trivial amount of scrutiny is pretty much off the table to begin with)
- If the goal is to stop the player from killing the shopkeeper or stealing shop contents, then make the shopkeeper not be a valid combat target and not allow the player to pick up his shop's contents without paying for them. This seems a little obvious -- almost tautological, in fact. But you asked.
Bonus points: He's down here because (according to point #1) he has to be here in order for the player to meet him, and it's presumably important for the game that the player meet him. And he's survived down here for the same reason: because he has to have survived in order for the player to meet him, and it's important for the player to meet him because if it wasn't important, we wouldn't have gone to the bother and expense of creating artwork for him.
Within the game fiction, he's survived because our world's mechanics are so thin that characters don't age, don't exercise, don't play Scrabble, don't sleep, and mostly don't eat (except occasionally in order to instantly repair themselves after being hit by a sword too often, often while the combat is still in progress). Characters don't require companionship to avoid becoming lonely, they don't require an occasional vacation, and they're happy standing stock-still on a single tile for eternity. Additionally, characters other than monsters and the player (and sometimes the player's companions) never even die, except in expensively-produced cutscenes with orchestral music.
And there's no space for an orchestra down here in the caves of doom.
Which, when you come to think of it, is actually a pretty good reason for the shopkeeper to want to live down here.