Your settlement was infiltrated by Synths. If you look where the bang happened you'll probably find a dead settler who has synth components on them, or if a settler just started randomly shooting then they're the Synth. I had this happen to me as well, when the Castle was attacked by Super Mutants. Turned out the person who started it all was a Synth.
Edit: Meant to post this as a reply to the other answer, but since it's here I'll say that if you check your settlers after you slaughter them, one of them will have Synth parts. That was the instigator. You can find out if you've been infiltrated by using VATS. Synths have Energy Damage Resistance, although you need a perk to see this. Even though you know it's a Synth, your other settlers don't, so killing the Synth will still make your settlement hostile.