Madara gave his Rinnegan to Nagato. But after Kabuto brings him back using Edo Tensei, he still has the Rinnegan. How is this possible?
A reincarnated individual will have all the abilities they had during their life, including kekkei genkai and kekkei tōta. They are psychically restored as they were at the time of their death, including any physical handicaps they may have possessed, such as Nagato's damaged legs.
Since Madara had the Rinnegan when he died, he is resurrected with it again (with the help of Kabuto's modifications, if you remember).
However, the Edo Tensei Rinnegans are fake. Although Edo Tensei Madara can use them to absorb ninjutsu, he can't use it to summon the Gedo Mazo, or use Limbo. It's kinda the same with Nagato's Rinnegan or Itachi's Mangekyo Sharingan.
For further proof, when Madara was revived in flesh through Rinne Rebirth, he lost his fake Rinnegan.
Actually Madara didn't give Nagato the Rinnegan,he only awakened it in him,and as he was an Uzumaki (which are distant relatives of Senju),he was able to control it.Madara got the Rinnegan by merging Hashirama's cells with his heart,awakening his Rinnegan very late in his life,after which he shortly died.That is why,when he was resurrected he had the Rinnegan.