Why does the lock screen sometimes appear when I'm not expecting it
This happens when you accidentally start to pull down the notifications menu (the thing that comes down when you slide your finger down from the top of the screen).
Unfortunately we have no way to prevent the lock screen and not compromise on security.