The medium absorbs all the colors that are complementary to the color of the medium.
So, when a light ray is passed through the medium, all the colors other than the color of the medium are absorbed. So teh light that comes out has only the subset of the colors of the medium.
hence the result
Note: It is not absolutely correct. It is true only for a monochromatic medium. I mean for mixed colors, the result will be intersection of the colors in teh medium and the incident light!
Recall an example: A red cellophane paper is put in front of a torch. The light that comes out is red!
Similarly, you put a red paper on the bulb. The color seems to be red!