This is my theory
Tobi is Madaras brother brought back to life with Madaras rinnegan before he died which is why Tobi gave Nagato the rinnegan so he would return the favor to his brother Madara at the rist of Nagatos life and not his own (looking back to when Tobi said the resurrection technique was suppose to be in his favor). Maybe explain why Madara knew of Nagato when he first came out, but idk how Tobi would have contacted him. Maybe in a failed attempt to bring him back? idk. That would also explain why Tobi backed off Kabuto when he showed Madara because he wouldnt be able to bring him back if he used him and he got sealed?