Why does it matter which way I put a battery into an electronic device?
UPDATE :  My explanation might not be correct.  Please read comments below.



Although knzhou gives a good general reason, I suspect that in this particular case your flashlight does not contain any non-linear components or diodes and the explanation is much more banal.  I suspect that the contacts in the flashlight are designed for the batteries to be a particular way round - ie with the spring at the bottom of a cell (-) and the tip of the bulb (or a strip of metal) at the top (+).  Then if you reverse the batteries the contacts will not make an electrical connection between the batteries and the bulb, because the spring does not touch the small + electrode of the cell.