Here's a theory: What if after Obito died when he was a kid, Madara used rinnegan on Obito. Obito was then controlled by Madara even after his death. Right now, Obito is just Madara's puppet.