They do that when they've engaged in CQC.
I suggest you make a small script that either makes them take ammo from corpses or add a handgun when they are out of ammo, so they don't get the handgun until absolutley necessary. Also, you could try to use the selectweapon in a loop until they run out of ammo, but I don't think that works.