Nexus 5 lock button behaves awkwardly i have a nexus 5 with lolipop v6 in it, for the last day, i've been struggling with the power button, as it acts awkwardly causing the entire phone to crash and restart itself.

Sometimes it fulfills its purpose and locks and unlocks the screen, and sometimes it would appear as the lock mechanism has crashed: it would lock, and then immediately return to the main page(a quick transition from black screen to main menu screen), sometimes it would engage the "power off" menu, as if i pressed the power button for couple of seconds.

Steps i've taken to try and fix the issue: 


I've removed suspecious programs
Engaged the safe mode
Reset device factory settings


none of those helped, saying that, each power button press does something, so i'd not say it's a "hardware" issue
It is possible that the button itself is damaged.

The button is made of 2 metal foils (one is flat, the other is a bit spherical on top) and if you press it, the sphere bends to the bottom foil and the connection represents a press. On my old Galaxy Nexus, dirt got under and it stopped reacting. Once I opened and cleaned it carefully with a knife it worked as the first day.

Considering you have the opposite problem, it could be the case that the spherical foil is somehow bent to keep sticking to the bottom even when you release the button. 

Since this requires you to open up the device, I suggest this as the last resort unless you ran out of other options. (Or send it in for a repair).