There has been a lot of unexplained thing throughout the Naruto series. For instance, how did the first Hokage die? The question of how did Madara get two Rinnegan is even bigger.
As we know Madara after being defeated by his friend and rival Hashirama Senju, used Izanagi to escape death and so live on to plot his next moves. Izanagi allows the user to cheat death even after a significant amount of time, as Madara did so he could be resurrected after his burial.
However, for a shinobi to use the Izanagi he or she sacrifices their sight in one of their eyes, as Madara and Danzo show us in the series.
Therefore Madara lost his sight in his right eye, which is shown in both the manga and anime, but then how did he have two Rinnegan when one of his Sharingan didn’t work? Well, it may simply be a hole in the plot but there may be another reason.
As we know the Rinnegan is one of the most powerful eye Jutsu’s in the shinobi world, and as a result awakening it could be powerful enough to restore the lost sight in his eye.
Now, this is only a theory of mine but it certainly does sound better than just a plot hole in the story.
This is not the only possibility; as we all know Madara as well as all the other Uchiha, swap and change their Sharingan quite easily. Madara, Obito, Danzo, Sasuke and Kakashi were all seen gaining and losing Sharingan, with the new user having full control of its powers.
Madara when finding Obito had already given his Rinnegan to Nagato many years prior to the third great shinobi war, and so the Sharingan he had when saving the young Uchiha was stolen from someone else.
So its possible that after Madara’s eye was rendered useless, he went on to find another strong Uchiha and stole his Sharingan, possibly during one of the great wars. There were a lot of casualties in that time; and therefore it would be easier to cover up a missing ninja.
It may be possible that only one of the eyes he had that turned into the Rinnegan, was actually his own.
These here are two possibilities as to why Madara was able to have two working Rinnegan after awakening them using Hashirama’s cells, and to me this is a better theory than it being just a plot hole.