Make Mac eject external drives when going to slumber or sleep/wake
There's a 3rd party app available for exactly this purpose. Jettison app automatically ejects your external drives when you put your MacBook to sleep.

It is a paid app with 15 days of free trial available.