I am replacing light fixtures in the bathroom from one fixture that was part of a medicine cabinet to 2 separate fixtures. The fixtures have 3 connections - black, white and copper which I have connected. I connected the lights and they come on but do not go off when I turn the switch off. They only go off when I turn off the breaker.The switch has 3 connections - 3 black tied together, red, and 2 white tied together. The black and red wires are connected to the switch and the white wires are capped together. There is also a red wire in the box for the light that is capped. How should it be wired so the switch controls the lights?
The red is your switched-hot, so connect the black from your fixture to that
It appears that your switch was wired so that always-hot could be passed along to downstream lighting outlets while providing a switched-hot at those outlets as well, while power comes in at the switch. So, you need to turn the breaker off and move the black wire from the fixture over to connect with the red wire from the ceiling instead of the black wires. Then you can button the fixture back up, turn the breaker back on, and enjoy your new switch!