(Theory, not canon) Madara pulled him out and Obito most likely wanted to repay him in any way then Madara started to tell him about the Uchiha, mentoring him, and slowly corrupting him to turn him into Tobi. I'm guessing he still kept an eye on Rin without being seen.
The nine tails attack was litteraly a YEAR after the Kakashi gaiden. She had to have died within that time period, what other inspiration would Obito have to attack the village?