I'm trying to change the mob's weapon if the player is near but it wont change

You need to use as not at to refer to the skeleton, at only changes the location of the command. Try execute as @e[type=skeleton,name="Soldier"] at @s if entity @a[distance=..5] run (command)