Why is my iPhone locking and trying to turn off by its self?

My iPhone has been trying to turn itself off and locking the screen for ages, at first i thought that it would go away but it hasn't, it also turns itself back on if i turn it off does anyone know how to make it stop?

You never need to actually turn an iphone off, I leave mine on 24x7 and just hit the mute switch at night. If its doing anything weird then just connect to itunes and restore to factory as I never heard of that happening

Your lock button is probably spoilt. Get it replaced. Hence it's being pushed in and causing it to lock/turn off/turn on every time.