Why is my Tablet randomly turning off?

A

AC Question

My tab is turning of.

So I have a Samsung Galaxy Tab 3. And here is my problem:
When I'm doing anything on my tab it just randomly turns off and when I turn it on next second buttons are not working, so I have to keep it turning off to unlock the keys again. Any idea why this is happening and how do I prevent this from happening because it is extremely annoying.