Are you getting any error message? Is it while you are doing anything in particular, or does it just happen randomly? The first thing that comes to mind is it is overheating. Do you have it on a hard surface with plenty of open air around it? I’ve seen older systems overheat and shut down when people had them sitting on a carpeted floor, which blocked airflow. Make sure the vents are unobstructed, so you can eliminated that.
I would also check and make certain that all the connections are secure, particularly the power and HDMI cable on both ends. Which brings up another possibility - is it shutting off when you turn off your TV? If so, some TVs can send shutdown signals over HDMI.
The last thing I can think of is if the power settings are configured to turn it off after a short period of time. I don’t have a PS4 in front of me at the moment, but I think that you can set it to turn off in as little as an hour, if there is no activity, and that can include while you are watching YouTube, Netflix or whatever.
I would give Sony a call if none of these are the issue.