Change the light in a room and the wavelengths reaching your eyes change too. Yet your red mug usually still looks red.
Color constancy is the visual system’s ability to perceive an object’s color as relatively stable under different illumination. The light entering the eye depends both on the light source and on what the surface reflects, so those two causes are tangled together. Your brain uses surrounding colors, context, and experience to make a useful estimate of the surface.
That estimate is not perfect or identical in every setting. In one real-world study, people matched familiar objects’ colors with high consistency across several room illuminations when given natural visual context. Color can still look ambiguous when the lighting cues are weak or unusual.