When you lägger something, that thing will be lying down afterwards.
When you ställer something, the thing will be standing up afterwards.
Bottles and books are good examples. Jag ställer flaskan på bordet but Jag lägger boken på bordet – typically we would place a bottle into standing position and lay a book down.
A gun will usually be seen as lying down in Swedish, so I would say lägg pistolen på bordet. For dropping the gun on the ground, one could either say lägga too, or use släppa, which has more the 'let go of' meaning.
If you ställer a gun, the gun would have to be in an upright position afterwards, this is difficult with most guns.