I am a huge fan of custom roms and have flashed many of them, it was all fine before. but suddenly, this problem was omni-present in all roms.
So i flashed the stock ROM version 4.1.2 (INDIA- XWLST) via mobile odin. it booted well after wiping cache and factory reset and was fine for a couple hours. After that the problem got massive. phone will restart or turn off when in screen-off. This continues even now in stock ROM. I tried everything from wiping cache, factory reset, dalvik cache wipe, fixing permissions and everything. But no results. THE MOST BIZZARE THING IS THAT PHONE IS FINE WHEN SCREEN IS ON. I experimented by keeping the screen on for an hour and nothing happened. THE MOMENT I PRESSED THE LOCK BUTTON, IT RESTARTS. Im going mad guys.. someone help meee..
EDIT: I think there's nothing wrong with the power button because it works well in all other places. If i remove the battery and reboot, I get a few seconds where i can lock and unlock screen. But again, it starts.