That happened obviously afterwards. Obito controlled him when he was around 13-14 and impersonated Madara at that time. I distinctly remember, Obito having long hair, the same as Madara when Obito was controlling Yagura.
Before the Rin incident, Obito wasn't corrupted.