Turning off or restarting iPhone if lock button is broken?
Solution 1:
I have the same problem with my iPod touch. In settings, go to "General">"Accessibility" and turn AssistiveTouch on. You will have a little square with a circle appear on your screen. tap that to open it up, and there will be a lock screen button. Press and hold this, and just like with the lock button, the "slide to power off" will appear. Good Luck!
Of course now you cannot power it back on as you have no power button... I had the same problem... Just connect the iPhone to your charger and it will power the phone back on.
Solution 2:
You have a couple options:
Simply let the phone discharge until it turns off. Then, you can charge it again and it should turn on when it reaches a high enough battery level.
If you dare, you can reset the device's network settings which will restart it (but obviously, also clear your network settings).
You can use Assistive Touch (Settings > Accessibility) to lock and turn off the phone.
But really, you should take it into an Apple store, so they can deal with the underlying problem of your broken button!