Lock axis (changable)

I am working on a 2.5D/3D sidescroller.
I need to lock and unlock the axis of a player based various triggers around the level.
when the level starts i need the X position locked, but in my game the player will make “turns” that will make it move along the x position so when that happens I need Z position locked and then back again.

didn’t realize this was an issue till i had some one else play it and they hit the “turn” to fast and the momentum of the X movement allowed him to fall off the platform when it switched to Z movement.

Diagrams would help.