Gun powder can explode when subjected to heat while confined. But a detonation is a specific type of explosion which produces a shock wave, typical of high explosives which do not need to be confined to explode. With the normal factory packaging, gun powder will not explode in a fire, as there is no confinement, but more importantly when gunpowder explodes there is no shock wave produced. This is proven with the following experiment. If you place a 1 pound gun powder cartridge on the surface of a bolder and initiate that cartridge, when the smoke clears, the rock will be unchanged other than burn marks from the powder. If you place a 1 pound high explosive cartridge on that same rock and initiate it, the rock will break. The difference is that the high explosive produces shock energy where the gun powder only produces gas energy. The old time powder men would say, "Gun powder shoots up, but dynamite shoots down." In rock blasting, shock energy is useful for breaking the rock, and gas energy is what displaces the rock. About 20% of the energy released during a detonation of a commercial explosive is shock energy and 80% is gas energy. The dimensional stone industry until recently used gunpowder to slab off rock without fracturing it, now there are low velocity waterproof emulsions that do a better job.