Why does High Sierra quit all my programs when I lock and close the laptop?
While I'm not entirely certain that this is the issue, you could attempt to disable graphics switching on your Mac.

In System Preferences, open the Energy Saver pane. From there, uncheck "Automatic Graphics Switching". To learn more about how to do that, check here: Set graphics performance on MacBook Pro

Note that disabling this setting will cause the discreet graphics to always be on. This may use more energy, but if this resolve the issue it would be helpful to know for troubleshooting.