The ability holder changes type whenever they are hit by a damage-dealing move (excluding Struggle, Shadow moves and typeless Revelation Dance). They will change according to the type of move they were last hit by. Getting hit while behind a substitute does not activate the ability. Even if a Pokémon had two types before getting Color Change activated, they will change to a single type. Status conditions are infliction before Color Change activates, meaning that they could still get status conditions other Pokémon of the same type would be immune to.
In the fifth generation, the final hit of a multi-strike move activates Color Change. Future Sight and Doom Desire will also now trigger Color Change when they hit (whereas before, they did not).