I like the opposite explanation better. The riddle keeps out the peasants who would just get themselves killed anyway. Once the adventurers get inside, the monsters are the real threat.
Puzzles and riddles are part of the genre. They're not part of modern culture though (at least not to a great extent). An encounter like Bilbo's with Gollum wouldn't work because the players probably wouldn't have any riddles handy. So instead they end up as part of a barrier or boundary.
When I GM I'm a little obsessed with making sure riddles make sense. I can justify an encoded message. I can't justify a guard that opens the door if you can answer a childish puzzle. If I do use a standard puzzle I usually preface it that the puzzle the players solve is an abstraction of what the PCs are solving.