There are several reasons for the catastrophic failure of these batteries, but the two most prevalent causes are a failure of the charging control circuit malfunctioning, and metal flakes shorting out between the anode (positive terminal), and the cathode, (negative terminal). Between the two terminals is the electrolyte which allows the ions to travel as the medium for power release that has been stored from the charging cycle. The electrolyte used in lithium batteries is flammable and the lithium is highly flammable in the presence of water. The space between the anode and cathode is very small making short circuits more likely. But, there are processes underway to make the electrolyte self extinguishing, and reducing the potential for damage.
Researchers at Stanford University have successfully encapsulated a flame retardant in a polymer called Polyvinylidene Fluoride, sometimes called the difluoride. The encapsulated flame retardant is triphenyl phosphate, a well known fire retardant. The polymer is close to what we know as Saran Wrap tm (Polyvinylidene chloride). The concept is extremely simple; as the polymer melts at 160 Celsius it releases the triphenyl phosphate when over-heating occurs extinguishing the fire. Incidentally, the technology extents to lithium polymer as well. The polymer is just the soft outer container with the lithium ion technology. The cover photo is a scanning electron microscope image showing the encapsulated TPP. Credit: Liu et al. Sci. Adv. 2017;3:e1601978 (Science Advances).
So, the trend is clear; safer batteries are possible and the technology that fostered the lithium ion battery also can be used to solve the problem of runaway fires...