Hello KIG16F,
Thank you for clarifying upon the issue you're facing as crash can define a variety of issues. With the Mac unexpectedly restarting when disconnecting the monitor it is recommended to confirm that macOS is updated. If macOS is updated, and you're disconnecting the monitor without exiting target display mode you may would want to exit target display mode to notate if the issue happens that way, then attempt the following steps.
How to reset the SMC of your Mac
Reset NVRAM or PRAM on your Mac
The troubleshooting in the following article could also help you determine what he possible cause of the issue is.
If your Mac restarted because of a problem
If you continue to have issues after completing those steps the next step would be to contact Apple directly via the Get Support website.
Have a great week weekend!