Check to see if its the phone itself , Because i had a similar issue on a galaxy s3 mini, when i would move it to fast or tap the back it would restart
Welcome to Android Central! Try reinstalling the firmware using either Samsung Kies or Samsung Smart Switch. If that doesn't help, it could be a hardware issue (either the Power button or the motherboard).