More questions than answers am I right? Well here's a couple more.
Anyway it sounds like there's an app running in the background maybe that is keeping the phone busy and then gets stuck for lack of a better way to put it. I'm imagining that the phone wants to close and lock but an app is running just enough for the device to be unsure if it's being used and kind of half locks. Not accepting input because it thinks it should be locked and also not displaying the lock screen because it's in this limbo. Turning the screen on and off with the power button settles the debate and brings up the lock screen.
Have you noticed a reduction in battery life?
Does the phone ever feel warmer than expected for being idle?
Does this happen after you've used a feature or an app?
Checking your battery use may help you identify such an app. Also check background apps. Clearing the cache for the background apps and possibly the partition cache may help with this for a while. Until the app acts up again.
Best wishes, let us know what you find and provide a few answers for more help.