He already knew that Tobi was not Madara. Also, by hypothesis, or maybe, he was watching the fight from a distance till Sasuke became hurt, and he came to help him?