Hydrogen peroxide used to be used to clean out bacteria from periodontal pockets. A dentist noticed that over time, patients using this technique had whiter teeth...and so whitening was born.
Most whitening solutions now use a different ingredient, but H2O2 works as well, just slower.