The chancellor ordered the execution of order 66 and the 501st helped Anakin now called Vader storm the temple. He deserted the 501st and Clone commander Appo took command. However Rex took out his inhibitor chip prior to order 66, being notified of the Chancellor's evilness by fellow clone, Fives.
The 501st legion, also called 'Vader's First', was a clone unit lead by Anakin Skywalker and Captain Rex. So just know that even though a Clone Captain had red markings does not mean that he still would after the change. For example a Clone sergeant and commander would have the same colors on their armor if they were in the same Battalion. Now the battalions and different branches all got unique marking. However when they switched to Phase II armor everything changed.
When clones had Phase 1 armor, the color markings were based on their rank. At the start of the Clone Wars such as in the Battle of Geonosis A clone with blue markings would mean he was a lieutenant while later on in the Clone Wars it would probably mean he was part of the 501st. Have you ever wondered why different clones sometimes had different markings and colors? Well It is actually either based on their rank or which Corps, Battalion or Legion they are in.