Keys become stuck for any number of reasons, but it is usually due to the lock pins inside the cylinder. The key moves the lock pins up and down to specified positions to allow turning of the cylinder. Removing a key that's stuck in the lock is usually a matter of patience.
Attempt to turn the key lock cylinder with the key completely to the right and then completely to the left. Turn the key until it is straight up and down and attempt to pull it from the lock.
Place your thumb on top of the cylinder next to the keyhole and press the cylinder inward. Hold the cylinder with your thumb and attempt to pull the key out of the lock. There is a pin in the back of the cylinder that sometimes becomes loose.
Wiggle the key up and down as you pull it from the lock. The wiggling action is usually enough to remove the key from the lock.
Spray some silicone lubricant into the keyhole. Wiggle the key up and down to help lubricate the pins inside the cylinder. Pull the key from the lock.
Grab the head of the key with a pair of pliers. Pull the key straight out of the lock using the pliers as extra leverage. Do not turn the key with the pliers as this might cause the key to break off in the cylinder.
Replace the lock entirely if the key will not remove or call a professional locksmith.