Hi and Welcome. My Name is ***** ***** I look forward to assisting you today with your question.
Sounds like it is going to sleep mode. Go to System Preferences > Energy Saver. Click on Power tab and set the sleep times accordingly. If this is laptop, click on Battery tab and set the time there as well.
If that didn't work, then which model of Mac is this ?
Let me know how it goes please