There are a few possible reasons why your external hard drive causes your computer to shut down (and what to do about it):
Mechanical damage – There may be something wrong with your cable, ports, or USB hub (especially if it’s powered). Try switching up your equipment and see if you can reproduce the issue. You should especially try testing your external hard drive on another Mac.
Compatibility issues – Western Digital (WD) external hard drives typically have compatibility issues with Mac. If you’re using this brand, try using a different enclosure.
Software errors – There may be a problem with the software-hardware communication on your Mac (for ex. your external hard drive is drawing too much power, causing the shutdown). Try resetting your Mac’s NVRAM, PRAM, or SMC.
Lack of resources – You may have a lot of devices connected to your Mac and it can’t provide enough power.