From the real world, before locking the cursor, the game shows the game menu and other stages where standard behaviour is required. And then, when the player presses the "Start Game" button, the game level loads and the cursor is locked. Conversely, when the player, for example, opens a chest in the game world, the inventory window opens and the cursor is unlocked.
In this case it would be more convenient to have some kind of interface for locking, a module method or message handling. As it is not clear why locking should be related to mouse click.
Maybe I don't fully understand the idea of a virtual cursor and this is the solution?