It seems that the Macintosh HD has been damaged so you can not erase it and Mac can't boot up from it. If so, you should repair the drive first and then try to reformat it again.
The error Disk Utility won't let you erase hard drive issue may occur to both the external hard drive and the Mac internal drive namely Macintosh HD by default. When you fail to erase the Macintosh HD, you can try these solutions:
Repair Macintosh HD with Disk Utility's First Aid:
- Boot Mac into macOS Recovery Mode.
- Launch Disk Utility and select your Mac hard drive from the left sidebar.
- Click First Aid at the top, then hit Run.
Format Macintosh HD in Internet Recovery Mode:
- Shut down the Mac and press and hold Command + Option + R or Command + Shift + Option + R to enter Internet Recovery Mode.
- Select Disk Utility and choose the Macintosh HD.
- Then click the Erase button to reformat Macintosh HD.