There are two types of stability, thermodynamic stability and kinetic stability.
Thermodynamic stability has to do with the energy of the products and reactants. A mixture of H
2 + O
2 will eventually produce H
2O because water has a lower energy (free energy to be specific) than hydrogen and oxygen. Water is a fairly stable molecule because it has such a low energy, and therefore we call it thermodynamically stable. In general, all processes will move toward minimizing free energy.
Although all processes go toward minimizing free energy, this principle does not say how fast this minimization takes. In some cases, thermodynamically unstable compounds will rapidly decompose to products that are more stable. However, sometimes it takes a very long time for thermodynamically unstable compounds to decompose. For example, diamond has a higher free energy than graphite, so diamond will tend to convert to graphite over time. But, why then do people say that "diamonds are forever"? Because, the conversion from diamond to graphite is extremely slow. Therefore, in this case, diamond does not stick around because it is thermodynamically stable, but because it is kinetically stable.
How do we explain kinetic stability? Every chemical reaction has what is known as an activation energy (
http://en.wikipedia.org/wiki/Activation_energy or better look it up in your chemistry textbook), the energy needed to overcome a barrier to reaction. In order for two molecules to react, they must collide with sufficient force to cross over this barrier. If the molecules don't have enough energy to cross the barrier, they can't react. The energy barrier for the diamond to graphite change is very large, so basically none of the carbon atoms in diamond have enough energy to cross the barrier and become graphite. This gives rise to the kinetic stability of diamond.
So what does this have to do with your question? H
2 and O
2 are kinetically stable at room temperature. The reaction of hydrogen and oxygen gas is very slow due to a moderately high activation energy. However, heating the reaction or providing a spark up gives hydrogen and oxygen gas enough activation energy to overcome the energy barrier that prevents them from reacting. In these cases, you can overcome the kinetic stability of the compounds and allow them to proceed towards a state of lower energy and greater thermodynamic stability.
I hope this clarifies things.