Lithium ion batteries have two electrodes sandwiching a layer of flammable organic solvent electrolyte between them. Mobile phone batteries are so slim that the gap between the wide, flat electrodes is tiny. In the case of the Samsung Galaxy Note 7, manufacturing defects squashed these electrodes and allowed them to touch. When that happens the battery short circuits and creates lots of heat. This speeds up the chemical reactions, which generate even more heat, leading to a thermal runaway condition.
Lithium batteries can also catch fire if they are overcharged, or charged below 0 degrees C. This causes lithium metal to build up on the negative electrode, which will also eventually cause a short circuit. Protection circuitry in the battery is supposed to prevent this, but this can also fail.
Subscribe to BBC Focus magazine for fascinating new Q&As every month and follow @sciencefocusQA on Twitter for your daily dose of fun science facts.