A pin tumbler lock only releases the key when the cylinder is back in its starting position. In that position, the pins drop into the cuts in the key and let it slide out. If anything stops the cylinder returning to that position, or stops the pins settling, the key stays trapped.
The common causes are:
The cylinder has not turned fully back. On most house locks, the key can only come out when it is vertical, or at whatever angle it went in. If the cylinder is a few degrees off, because the bolt is binding or the key was released too early, the key will not come out.
The bolt is binding. If the deadbolt is under pressure from a misaligned door, the cylinder cannot rotate back freely. The key is held by the tension on the bolt.
A worn or poorly cut key. Copies cut from copies, or keys worn thin over years, can sit slightly wrong in the cylinder. The pins catch on a rough edge or a cut that is too shallow, and the key drags on the way out.
Worn pins or springs. Inside an old cylinder, pins wear and springs weaken. A pin can hang up on the key rather than dropping cleanly.
Dirt, grit or old lubricant. Grit and gummy oil stop pins moving freely. This is common on exterior locks that have been oiled with household oil, which collects dust.
Ice. In winter, moisture inside the cylinder can freeze around the key once it is inserted, especially on a lock that faces the weather.
A bent key. A key that has been used to pry, bent in a pocket or dropped under a car wheel may go in but bind on the way out.
The wrong key. A similar key from another lock may go in far enough to lift some pins but not others, and then catch.