How does a gun fire on its own?

Basically, it doesn't. A gun is an inanimate object, not capable of movement of its own accord. Your car does not start and drive to the gas station, your lawnmower does not start up and cut grass without someone doing something, like turning a key, pressing a switch, pulling a starter- or pressing a trigger.