This is a brilliant question, I’ve never thought about it before! I think it’s something to do with the structure of foam, and how colour works.
Nothing in the world actually has a colour – colour comes about because different surfaces reflect different wavelengths of light. For example, if a surface absorbs all wavelengths of light apart from the green portion, then because it’s only the green bit that bounces off it and into our eyes, we see it as a green object. Likewise, if a surface reflects all wavelengths equally, it looks white. When you have a red shampoo, say, it looks red because the liquid is absorbing all of the non-red wavelengths of light. When you lather it up though, you completely change its structure – it goes from being a liquid, to becoming a foam, which is made up of thousands of tiny little bubbles. The surface of these bubbles will be different to that of the original shampoo liquid, and will reflect all wavelengths of light instead of absorbing most of them. As a result, it looks white, instead of red.