There are two most likely reasons the key will not come out in the locked/unlocked position.
One is that the stop on the back is installed wrong, the other is that the cam is hitting something and preventing the lock from turning the full rotation.
I would take the small nut off the back, remove the lock tab, cam and stop, then turn the key and the lock should turn 360 degrees with the key coming out in three positions, the three indents. This will confirm that the lock is ok, but that the installation is preventing the key from removal.
Find the two indents where the key comes out and the cam is pointing the two directions you want it to, then put the stop on the back such that the key still turns the cam the two directions you want, AND that the key comes out in both positions. Then put the cam back on, the lock tab and tighten the small nut.
If at this point, the key again will not come out in either position, then the cam is hitting something preventing it from rotation the full 90 degrees. If this is the case, then find out where it is touching, and either bend or grind the cam a little to allow the cam to fully turn.
**Please note on some aircraft where the Baggage/Panel is located in the nose of the aircraft, the lock is designed NOT to release the key when the panel is unlocked for safety.**