Mac goes unexpected to sleep
pmset is the terminal command to display all things sleep on OSX. man pmset shows you how to use the binary, pmset -g shows you the current settings.
It is possible to restore pmset to defaults by using the following commands (whilst sleep setting defaults differ from Mac to Mac, but apparently Apple have usefully made the numerical value that refers to the various profiles relatively the same.)
sudo pmset -c 2 -b 1 -u 1; pmset -g
[Sudo will require your password]
This last command from here: Default settings for pmset -g?
Another suggestion is to reset PRAM and SMC:

How to reset PRAM
1.Shut down your computer

Press the Power key
Immediately press Command + Option + P + R keys
Hold down the keys until your Mac reboots
Let go of the keys

To reset SMC

Turn off your Mac
Hold down Control + Shift + Option and press power
Hold the buttons for 10-15 sec
Release the keys and restart your Mac