When the mouse locks in game, you probably hit the H key. Thats the default key to toggle the mouse to flight controller and unfortunatly works also if you have a Joystick installed.
To "remedy" - just hit H key again.
To avoid the problem in the future (if you have a Joystick that is) - go to OPTIONS > CONTROLS > Map Keys and unmap the "Global - Mouse Control Toggle" (clear key).