Why are lithium-ion batteries typically used if they’re so flammable?
Li-ion is primarily chosen for higher energy density (by weight and volume), but also for higher power, higher voltage, more flexible form factor, cheaper and easier manufacture, more efficient charging, lower self-discharge, more cycles and higher reliability than most other battery types. 




  Why don’t electronics companies try a different type of battery, like
  nickel-cadmium, or nickel-metal hydride?


They have. Cadmium is a heavy metal, so Nicads are out. NiMH batteries were used in phones and laptops before Li-ion took over. Charging them was always a problem due to heat generation and the difficulty of accurately detecting full charge.  


  lithium-ion batteries ... have exploded. Granted that these are not so common occurrences,
  but the fact that they happen at all is still troublesome.


You know what's really troublesome? 

17 car fires every hour in the US, killing an average of four people every week.

Yet nobody is concerned enough to stop using gasoline, because its enormous energy density (effectively 20 times greater than Li-ion) is worth the risk.