mpoinar wrote:
[...]
And will this prevent the mac from shutting down and restarting when I open the lid?
No, this won't address the shut downs at all, only the auto-start when opening the lid.
At this point I'm out of ideas as to why it is shutting down.
Under normal circumstances, shutting down is not supposed to happen simply by closing the lid of the computer. It also is not default behavior for a Mac to be silent when it reboots, though that startup chime can be silenced in System Settings. It's this particular detail that suggests to me that the Mac is simply logging you out of your user account.
A reboot would typically be accompanied by the startup chime, then the login screen would appear, and when you've logged in again your apps and previously open windows would reopen, if that is your preference.
When you log out your user but do not shut down the Mac, your applications windows are closed and the apps are quit. If you close the lid after logging out, then the screen obviously goes dark. Now when you open the lid, the Mac only has to present the login screen so there is no chime. Then after you log in, all of your apps and their windows would have to reopen, just as if you had restarted.
You can observe this behavior yourself by selecting Apple menu > Log Out (User)... and then let the timer run out.