There are a number of ways.
Many toothpastes contain sodium percarbonate or calcium peroxide. Both of these chemicals release hydrogen peroxide when they are mixed with water. In the toothpaste they are more stable than plain hydrogen peroxide would be, so the toothpaste won’t decompose before you have a chance to use it.
Your teeth can be yellow for several reasons. Peroxide toothpastes, or a rinse of 3% hydrogen peroxide can help most of them.
Many of the foods you eat can stain the teeth. Coffee, tea, and tobacco are famous for yellowing teeth, but many other foods also have this ability. Peroxide bleaches the yellow by oxidizing the stain molecules so that they no longer absorb light.
Bacteria that live in the mouth make a protein film on the teeth (called a biofilm). This is easily stained, and may be slightly yellow all by itself. Peroxide bleaches the stain molecules, but it also breaks up the protein film, so you can brush it away.
If you have been brushing your teeth for many years, the white enamel on the outside of the tooth may get thin enough that the yellow dentin inside the tooth shows through. Peroxide can penetrate into the dentin, and bleach the yellow to a whiter color.