One answer I've seen in literature is to set up a convincing illusion to disguise the deeper secrets of the building. In his book Bands of Mourning, Brandon Sanderson presents an interesting twist on the typical dungeon filled with puzzles and traps (major spoiler alert). The characters run into a stereotypical set of pit traps, acid traps, swinging weapons, tile-activated traps, etc. All of this supposedly protects a powerful weapon. However, the characters don't find this entirely logical.
"The ones who built this place were charged with protecting the Sovereign's weapon. They knew others would eventually follow, and so the builders were bound to make it difficult, knowing that they could not remain to guard in person..."
"Why would your people build such an obvious resting place for the Bands? Why make this temple, which proclaims thatsomething precious is inside, then go to the effort of making all these traps? Why not just hide the Bands someplace unassuming, like a cave?"
"They are a challenge, like I said..."
"You told me the sovereign left his weapon there with order to protect it because he was going to return for it, Right? ... Wouldn't they have been worried for your king's safety?"
Unfortunately, the logical place for the prize appears to have already been looted, but they realize the traps and fake treasure room were only to fool them and make them think they had solved the challenge, when the weapon was hidden elsewhere. They then find a hidden side chamber with what appears to hold the real weapon.
"Those traps... those traps are stupid. What if one did catch him?
The whole things has to be a decoy..." Since the weapon was easy to
hide, "only someone who knew what to look for could use your weapon.
And in that case, the people who built the temple could have left the
weapon where the returning Lord Ruler would see it, but everyone else
would pass right by, digging farther into the temple to encounter
traps, pits, and decoys, all designed to either kill them or convince
them they'd successfully robbed the place"
It gets worse, though. (Serious Mistborn spoilers ahead. Read at your own risk!)
The "real weapon" they find in the side room is without power, leading them to believe it's already been used and then returned here, depleted, without recharging it. It's not until later that they realize it's yet another layer of fakeout for extra-determined looters! The actual weapon was shaped differently than what they expected it to look like, and placed on a statue outside of the dungeon, where its owner could come to retrieve it without having to deal with any hassle at all, but other people would easily overlook.
This all makes a lot more sense at the very end of the book, when Waxillium finds a stored memory revealing that the Sovereign is not, as they had assumed, a reincarnated Lord Ruler -- for whom all this stuff would have been quite out of character -- but actually a reincarnated Kelsier, a rebel against the Lord Ruler who loved messing with people's heads and fits quite well into the trickster role.
So in summary, the puzzles can be a distraction to stop you from digging too deep into the secrets or the place and feel like you've explored enough. They set up a linear route down the path which a clever designer can use to give the user tunnel vision.