"I did not know the cursor wasn't locking sometimes. Does it help to hit escape and then click?"
It is hard to tell since once I enter a menu and then leave it or when I enter into a dialogue with another NPC the cursor disappears as intended, but when the cursor was visible after I started playing it could move wherever it want and that's a problem if you play in windowed mode.
I think that even if the cursor was invisible it could still move outside of the window. That's my point it should never be able to move at all during a playthrough, unless it is needed (Like when you're actually in a menu).