iphone wont turn on
So, my iphone 5 keeps turning itself off after I send text messages or just press the lock button. This started about 3 days ago. Today it turned itself off and wouldn't turn on no matter what I did. I tried reseting it, I tried holding the lock button and home button at the same time for 30 seconds. It still didn't turn on. 2 hours passed and I decided to shake my phone then press the lock and home button (i don't know why I shook it but thank God I did) and it turned on. I'm glad it's working but I want to know what the problem is. I know it will probably happen again because this is too good to be true.
iPhone 5, iOS 6.1.4