I stopped destroying the machine guns and yeah even if marked as "friendly" and you have the settlement they'll still attack the hell out of my machine guns. I was going to try and move them to the one side that gets attacked but didn't know if my guys would get cut down if they went near them. So deleted them with method below. This is the best/unmodded way to clear it for your personal use.
This is how I do it...
Start my attack or do the quest/side with guy/girl.
-this way they all come out of the area and you can kill them/lead them wherever needed.
-that gets rid of bodies inside
When all the npc's are dead I run into the store/medic area and hide until the machine guns reset.
-Sneak over to the workbench/claim the settlement.
-then you can hold the pickup button and place them on a slab of concrete/wood ground and slightly lift it to delete them.
-I froze my game once by doing this but other than that it works perfectly. ( I should note it was because I tried to lift/delete everything at once and screwed up so they wanted to reload all at once I guess. )
Or you can side with them and delete/place your own turrets( and beds if wanted ) the same way noted above.
The locked doors can get annoying but because we have the keys permanently what I do is leave one closed/claim it as my own and leave the others locked but open. They tend to stay open if I open them and leave. Think it has to do with the a.I. of settlers thinking its locked/not wanting to close it. Or ill delete the doors altogether but I hate doing that...