NPCs lose their weapons when they disengage or when the player dies and returns. It’s very easy to test: just die in front of an NPC, and when you come back, they no longer have their weapons. It’s the same with NPCs that have multiple attacks in their inventory, such as animals or bosses. With each death, they lose one, and eventually, they will have none left and will only follow you.
The test was conducted on an online vanilla server.