There actually are certain circumstances or parameters to be met for settlers to better arm themselves. For starters, I can verify(in all my experiences) that the settlement does, in fact, need to be under attack. Settlers will most often go for easily accessible melee weapons, especially legendaries. They're also very quick to loot fallen enemies of any and all better equipment. Another requirement is ammunition. A settler will only pick up a ranged weapon if a.) they have at least one round of ammunition that the weapon requires in their inventory already or b.) the weapon and ammo said weapon requires can be obtained together in one transfer, i.e. from the same container, or off of the same fallen ally/enemy. Same applies for power armor and fusion cores. Also, I've noticed that if there is a better variant of a weapon nearby but is inaccessible to settlers, they won't pick up any lesser variants, even if a lesser variant is better than what they currently have equipped. For instance, I keep all my legendaries in a secured room on the fourth floor of a structure I built. The only way a settler could get access to those containers is if they spawned inside that room upon the player character fast traveling into that settlement. So, if a raider drops an advanced assault rifle with 5.56 rounds and all my settlers still have boards and pipe rifles, they still won't grab the assault rifle as long as I have my two shot variant 20 feet away. I noticed this when I had a set of raider power armor with a fusion core left in it for settlers to use during an attack but they would never use it. Leave the fusion core in my x01 model with shark paint, and they hop into that thing to chase radroaches down. Again, this is what I can verify via personal experiences.