Why won't my Fallout 4 settlers keep weapons equipped?

NPCs not only need to be given weapons, to fight; they need to be given ammunition, too.

If an NPC runs out of ammunition for their gun, it is expected that they would equip the closest suitable weapon they could use, which would be the fists if no other melee weapon was available.

Companion NPCs are slightly different, in that they will have a unique weapon that can't be taken from them. This weapon will have unlimited ammunition.