Slam-fires have a multitude of causes. Marginal hammer-sear engagement (from wear, chipping, alteration, packed dirt, broken or missing sear spring, etc.) that allows the hammer to jar loose from the impact of the slide or bolt shutting is not uncommon. In guns that do not have a secondary ("safety") hammer notch, the result is a slam-fire. Same is true with guns that just aren't made right, and have parts out of tolerance; all kinds of malfunctions are possible, as S&W learned --expensively--with its PP-series pistols.
Any firearm that has a propensity to dimple the primer from firing pin inertia is a prime candidate. I have induced slam fires in certain military rifles by once or twice ejecting and re-chambering the same cartridge; each time the dimple gets deeper.
A broken firing pin or one that is jammed in a forward position can cause a slamfire, as can any piece of solid debris stuck on the bolt face. In rimfire guns, insufficient headspace can cause slam-fires. High primers have already been mentioned, but there are also differences in ammunition. Early USA-made Walther TPH pistols experienced a rash of slam-fires with some brands of US ammo, due to insufficient headspace. It turned out that Walther's drawings were dimensioned to European rimfire, which had rims thinner than SAAMI allowable maximum. Headspace was opened up, and the problem went away. Also with rimfires: a stuck extractor can act like a firing pin.
There is also the issue of primer sensitivity. While primers are made to close tolerances measured in a range of inch-ounces (at one end NONE should fire, and at the other, ALL should fire), primer-making is part alchemy. QC cannot be verified except by sample testing. So one should not assume that he'll never encounter an unstable or supersensitive primer which, indented with an otherwise harmless dimple, will fire. Add amateur handloading to the equation, and the possibilities of ammo-related problems increase exponentially.
There are probably eighteen more potential causes of slam-fires that don't spring immediately to mind, but they are out there, waiting.
So hold the gun rigidly, and point it in a safe direction when chambering.
M