It is the screen turning “Off”, that has macOS putting the Mac to sleep. Not to be confused with the screen saver, which puts up pretty pictures or animations while the screen is still powered on.
The Screen Saver can also require you to enter a password.
System Settings -> Lock Screen -> Start Screen Saver when inactive -> 1 min, 2 min, 3 min, 5 min, 10 min, 20 min, 30 min, 1 hr, 1.5 hr, 2 hr, 2.5 hr, 3 hr, never
System Settings -> Lock Screen -> Require password after screen shaver begins or display is turned off -> 1 min, 2 min, 3 min, 5 min, 10 min, 20 min, 30 min, 1 hr, 1.5 hr, 2 hr, 2.5 hr, 3 hr, never
Amphetamine is a popular 3rd party app that prevents the Mac from going to sleep. The 'caffeinate' command via Applications -> Utilities -> Terminal can also be used to prevent a Mac from sleeping (man caffeinate)
Or you can keep the Mac awake longer by changing System Settings -> Lock Screen settings:
Using the Battery:
System Settings -> Lock Screen -> Turn display off on battery when inactive -> 1 min, 2 min, 3 min, 5 min, 10 min, 20 min, 30 min, 1 hr, 1.5 hr, 2 hr, 2.5 hr, 3 hr, never
Using the power adapter:
System Settings -> Lock Screen -> Turn display off on power adapter when inactive -> 1 min, 2 min, 3 min, 5 min, 10 min, 20 min, 30 min, 1 hr, 1.5 hr, 2 hr, 2.5 hr, 3 hr, never
If you are plugged into Power, there is a setting to stay awake when the screen turns off. Does not work when using the battery:
System Settings -> Battery -> Options -> [X] Prevent automatic sleeping on power adapter when the display is off.
You can set a Hot Corner, such that when you place your cursor in that corner it disables the screen saver. However, this requires you to remember to put your cursor in the hot corner whenever you leave your desk.
System Settings -> Desktop & Dock -> scroll to the bottom -> Hot Corners... -> Pick a corner -> "Disable Screen Saver".
If you wish, you can look at the sleep event log using the following Applications -> Utilities -> Terminal command:
pmset -g log | grep -e ' Sleep ' -e ' Wake '