Madara sustained injuries in his battle with Hashirama, but he also got ahold of Hashirama's DNA. He also stated that he awaked his rinnegan shortly before death. How long he was alive before he died we do not know, but he stopped acting out as Madara Uchiha after such point.
Tactically, it would be beneficial to Madara, now close to death, to find Uchiha heirs who
1. Shared his hatred for the Village of Konoho
2. Were not strong enough to weild his weapons that he left to them.
If Madara Uchiha was going to die, it would be wisest to entrust his power - i.e. his rinnegan, his other sharingan with power capable of controlling the 9tails, his library of Sharingans, his incredibly powerful fan that we know Tobi weilds, and lastly Zetsu.
Zetsu - combination of the two strongest shinobis known to live, and a vast vast wealth of knowledge. Zetsu could have recorded what madara read on the Uchiha stone Tablet, information on how to fight ninjas, how to utilize and activate sharingans and which sharingans had certain powers (ie amaterasu, or Kamui, or kotoamat..), information on space/time jutsu. I also ponder over the idea of Tobi training in the other dimension to defy aging...
So a young angry half destroyed teenager was given crazy gifts and possibly training before Madara'd death. It could logically be Obito, or any other Uchihas with feelings of hatred to konoho.