Why build a trap?
1. Password protection. That is - you're hiding something, you want to come back for it later, you want to ensure no-one gets to it before you. Knowledge of how to circumvent the trap is the password.
2. Military strategy. Could be a component of fixed-location-defense (murder-holes, false gates, landmines) guerilla warfare (spike pits, different landmines) or part of an ambush. Basic premise - make your enemy fear to enter a location, or punish them for entering it, or both.
3. Hunting technique. Webs and snares. Potentially nonlethal. Main purpose - physically restrains a prey creature so you can devour their succulent heart.
4. Disbarment. Not the same as defense - this isn't about keeping an enemy away from something of tactical value, it's about keeping everyone away from something that it no-one should have. When burying an artefact under sixteen tonnes of stone isn't enough to keep it out of people's hands, fill a corridor with scythe pendulums, parasitic wasp nests, explosive runes, gorgon-eye jewels, mirrors, false-mirrors hiding doppelgangers, ooze monsters, wand of fireball, large blocks of gelignite carved to resemble ooze monsters, ooze monsters disguised as bars of gelignite, lamp oil laced with napalm, oil bottles with warning labels containing small font explosive runes, word puzzle that must be completed to open final door (spells out "explosive runes".)
5. Shits and giggles. You have a sense of humour / justice / revenge based around pulling the wings off flies. Death traps are what you do instead of lathing table legs. Basically a craft hobby.
6. Don't build a trap. Then something happens. Example - bottom fifteen feet of a shaft containing a cage elevator floods with water, elevator continues working. Elevator gradually fills with the bones of people who don't notice all the other bones in the elevator.
7. Scourge the unworthy. You don't want some chickenshit lifting the Crown of the Everchosen. Make them earn it. (Likewise - coming of age rituals, learning the inner mysteries of a temple, romancing an Elf lord/lady, buying shit at Argos.)