What is preventing my phone from staying locked? Normally, when I press the power button on my phone, the screen turns off and when I press it again, I'm presented with the lock screen.  (I don't have a password or pattern, so it's just the "Swipe up to unlock" screen.)

In the last month or so, my phone has started exhibiting the symptom that I press the power button and the screen turns off, but when I press the power button again, it's not at the lock screen, but whatever the front application happens to be.  Sometimes I'll note that about 20 seconds after I press the power button to lock the screen, the phone will emit another sound from the speakers that sounds a lot like the "I've just locked" click.

This doesn't happen all of the time.  At a guess, I'd say that about a third of the times that I wake from a black screen, I get no lock screen.  Also, I'm not sure if pressing the power button to lock vs. a timeout makes any difference.

It seems to me that there must be some application that's keeping the phone from locking, but I think I've uninstalled all the applications that I installed shortly before this started happening.  I'm guessing that it's an application that had been recently updated, but I don't know how to track that down.

I don't really want to uninstall apps one-by-one, as I can't reproduce the problem.  It never happens when I want it to.

Does anyone have any ideas how to track down this problem?

This is on a Nexus 5 running 6.0.1, rooted.  (I never do anything with root, though, and it's preventing me from upgrading, so I should really undo it.)
Since you suspect this to be app related, install wakelock detector which should help you identify the wakelocks that are holding the screen awake. Read the Screen Wakelock section

Once the culprit is identified, Googling for that would lead you to the app, if the app name is not evident ( You may need to monitor over a few hours repeatedly, since the behaviour reported is not consistent)

Edit: Remember to monitor when the phone is not being used. Charging the phone to a fixed percentage like 90% before retiring for bed would be ideal monitoring time