Because there is a net energy gain.
The bonds between the two O's and the two H's (times 2) makes them stable, so they won't normally turn into water, even if both are mixed. But if you provide enough energy to release that bond (called excitation energy) you create some single O's and H's.
They can recombine as H-H or O-O, but if they combine as H-O-H they go to a lower energy level (This means MUCH more stable), and release the excess energy, mostly as heat, that will cause other H-H and O-O pairs to dissociate, and these are also more likely to H-O-H
In practice this means, that a mixture of 2 H2 and 1 O2 is 'stable', but a single spark will make it explode, because the water that is formed, is in the form of high-pressure vapour.
Extra: same goes for mixtures of dihydrogen and dichlorine. They can even be "ignited" by sunlight.