Why does ‘dungeon’, in the context of roleplaying games and D&D in particular, mean the places adventurers go to kill stuff?

I'm asking because ‘dungeon’ usually means a kind of prison, and I can't see how it evolved into “hunting ground”, or however it’s used in D&D.