For quite some time I have been running into an issue with MacBook logging out after I was inactive for long period of time. This behaviour seems to have started after I upgraded OS to Sierra. Initially I kept investigating along the line of thinking that my MacBook Pro has been crashing due to some application that may be running and having some issues during hibernation. After looking at al diagnostic and system reports, I could not find any indication of crash report around the time when laptop used to logout. I stepped back and looked at statement of my problem. The key to this was "inactivity" for long period of time. Thats when it struck me that there should be an option or setting that is related to "inactivity" and logout. Yes, there it was.
You will see following pop-up with option that affects behaviour when there is prolonged period of inactivity.