How do I lock the mouse to the viewport?

Can you check in your Editor Settings -> under the “Level Editor” section click on “Play” then in the settings that get displayed, see if “Game Gets Mouse Control” is enabled, if it is not turn it on and try playing the game again. should keep the mouse within bounds with the Lock Mouse to Viewport turned on.