Rechargeable lithium batteries are more susceptible to overheating than other types of batteries if they are exposed to high temperatures, are damaged or have manufacturing flaws. Once the overheating starts, it can lead to "thermal runaway" in which temperatures continue escalating to very high levels. Water can put out the flames, but doesn't always halt the thermal runaway. Flames will often reappear after initially being quenched.
The science behind phone battery fires is actually pretty simple, and fairly well understood. Much like the infamous exploding hoverboards, phones use lithium ion battery packs for their power, and it just so happens that the liquid swimming around inside most lithium ion batteries is highly flammable.
If the battery short-circuits -- say, by puncturing the incredibly thin sheet of plastic separating the positive and negative sides of the battery -- the puncture point becomes the path of least resistance for electricity to flow.
It heats up the (flammable!) liquid electrolyte at that spot. And if the liquid heats up quickly enough, the battery can explode.