Soap bubbles are mostly water and, how we can see every day, water reflects part of the light that hits it. So, when light arrive on a bubble, some of it bounces right off the surface, like it does off the surface of a lake.
The rest enters the thin layer of soapy water that forms the bubble. Light travels peacefully through all of it, until it reaches the other side: the surface between the water and the inside of the bubble. Like the external one, this surface too reflects a little. So a bit of the light that entered is forced to go back where it came from.
As soon as these rays exit the bubble, they meet the ones that are bouncing off the exterior of it. When these two waves meet, they interfere, as waves do.
Different colors—that is, different wavelengths of light—exit more or less synchronized with their counterparts bouncing off. Sometimes they are in synch (or in phase, if you wanna sound sciencey), and they amplify each other, other times they are out of synch and they cancel each other.
Colors that exit amplified appear as a faint glow on the surface of the bubble.
The thickness of the water layer determines how in synch the two waves are, and therefore the color we see. A teeny tiny change—a spot a little thicker or with a little more soap—is all it takes to change the color that gets chosen. And since these changes are gradual, the glow goes through all colors in between, creating amazing small rainbows on the surface.
We actually use that very same property for anti-reflection coatings on lenses. The coating is made of layers of different thickness, each engineered to cancel out a specific color. Put them together and they cancel all colors that would be reflected. Indeed, if you look at a lens from different angles, you can see light reflecting differently and some shades do appear.
So next time you see a soap bubble, maybe take some time to admire its magical surface. Maybe just a second, before you surrender to the irresistible temptation of popping it.