A point of terminology. Both deflagration and detonation are forms of combustion. By definition, deflagration is combustion at a rate below the speed of sound in the explosive material. Detonation is combustion at a rate above the speed of sound in the explosive material.
Gun powders can both deflagrate or detonate. In general, they deflagrate because the shock wave needed to present ignition energy for detonation does not transfer efficiently between small divisions (grains) in an explosive material that's not very shock sensitive. However, if you get a large enough pile in one place it can be detonated as the high inertial resistance of the surrounding mass allows the powder to compress enough at the leading edge of the shock wave to carry the wave forward through the grains, growing the explosion by further compressing the powder at its leading edge. Black powder is the same, but an even larger pile is needed. If you get one large enough (IIRC it needs to be several tons, but don't take that as gospel because my memory isn't clear on that) it can be detonated by a dynamite primer.
Detonation in firearms should theoretically never occur with any powder because of the grain divisions and relative shock insensitivity of the core material. However, in poor ignition there can be enough heat to fuse the grains together so the mass becomes contiguous. This is not an uncommon occurrence in loads that squib out because the powder started to burn, but later extinguished. You often find in such cases a lump of powder that is yellow from the graphite and outer layer having burned off, and that is a collect of fused grains. Such a lump can carry a detonation wave, and light loads or loads using powder with too slow a burn rate and showing spotty ignition and leaving irregular amounts of unburned powder behind are much more likely to squib out and fuse than a full load with adequate pressure.
Once fused, to get detonation all you need is an initiating wave. There have been lots of theories about this initiation occurring because of additive waves bouncing around in the empty case. The same thing was once theorized as a cause for gas/air mix detonation (knocking in engines). But after transparent cylinders were made of special glasses and ceramics and the phenomenon was filmed, it was found it always initiated at the hottest spot in the cylinder, regardless of what gas waves were doing. My guess is the same thing occurs in cartridge case detonations. First you get the fusing, but then some spot in the mass manages to sustain some level of deflagration, so it stays hot and initiates the detonation. I don't know if the exact mechanism for why this should happen is understood. Broadly, though, the fused mass will be hotter than normal itself, and the higher you heat an explosive, the less additional energy it needs to combust. Why that would grow into a shock wave in one instance and not in another, I don't know. The term "bad luck" comes to mind.
The Finnish Gunwriter's site describes a 308 rifle that was blown apart by a 3.1 grain charge of N320, a pistol powder with about the burn rate of 231. The cause is not a double-charge, as you'd need about five repeat charges that size just to reach normal 308 pressure. So I think perhaps the grains separated in all that empty space and the primer burned some, but not others, and the others were all in one place and got hot enough to fuse without igniting, and afterward a hot spot either from a late primer spark or the previous burning portion touched it and did what happens in knocking.
You can get a theoretical half-million psi at the powder lump location that way. Detonation, because it is faster than the speed of sound, occurs faster than the gas evolved can get away from the lump. This would make a temporary very high pressure region that could start a crack before the gas expands to fill the case. Such cracks need only a few hundred psi to finish breaking apart, and that's why such a small charge could cause such damage even if its final expanded gas pressure is too low to hurt the gun.