Is there a way to lock a rotation? So that the keys that are set to rotate in that axis only work when they are in that axis?

For instance i have a player object that is set to rotate around a object by 90’ degrees every time i press a key.

I have the D key set to rotate by -90’ degrees around on the Z Axis counter clockwise.
and the A key is set to rotate back around by 90’ degrees on the Z Axis clockwise.

The W key is set to Rotate/Roll by -90’ degrees on the Y Axis counter clockwise.
and the S key is set to Rotate/Roll back around by 90’ degrees on the Y Axis clockwise.

Keys A and D work fine and so do Keys W and S until i try to go back to rotating on the Z Axis. Its like keys A and D
Get Stuck in the Y Axis and they begin to rotate around the Y Axis Just like Keys W and S. and i end up having to randomly press the keys until it snaps out of the Y Axis.

Any help would be greatly appreciated