Mandavya Muni was a great sage (cf. SB 1.13.1), and Vidura was formerly the controller, Yamaraj, who takes charge of the living entities after death. Birth, maintenance and death are three conditional states of the living entities who are within the material world. As the appointed controller after death, Yamaraj once tried Mandavya Muni for his childhood profligacy and ordered him to be pierced with a lance. Mandavya, being angry at Yamaraj for awarding him undue punishment, cursed him to become a dra (a member of the less-intelligent laborer class). Thus Yamaraj took birth in the womb of the kept wife of Vicitravirya from the semen of Vicitravirya's brother, Vyasadeva.
This story is elaborately told in the following section of Mahbhrata:
There was a celebrated brahmin named Mandavya who was determined on the spiritual path. Steady in truthfulness and austerity, he knew all the religious law. Mandavya was a mighty yogi capable of great asceticism. Beneath a tree at the entrance to his rama, he stood unmoving with upraised arms and observed a religious vow of silence. Much time passed, until one day, as the sage dutifully performed his penances, a band of thieves rushed into his rama carrying stolen valuables. Being followed closely by a large group of police, the frightened thieves quickly concealed their booty in the sage's cottage and then hid themselves in the same spot, just as the heavily-armed policemen arrived there.
Seeing the sage, who stood silently with upraised arms, the police captain anxiously questioned him, "Brahmin, which road did the thieves take? Whichever way they went, we have to follow them immediately!
Even when thus questioned, the sage maintained his religious vow of silence and spoke not a word, true or false, to the police. At that point the king's men searched the sage's rama and quickly discovered the thieves, together with the stolen property. The police then suspected the sage of complicity in the crime. They arrested him and delivered him with the thieves to the king.
The king then sentenced the sage and the actual thieves: "Let them be put to death! The government executioners, not realizing that Mandavya was a holy ascetic, impaled him on a lance and left him in that condition. The guards then returned to the king and took their valuable reward.
Although that most religious man remained impaled on the stake for a considerable time without food or drink, he still did not die. Mandavya was such a powerful yogi that not only did he keep himself alive, but through his mystic power he was able to summon his fellow yogis to that place. That night, many saintly sages, assuming the form of birds, came there from all directions and by their own mystic strength revealed themselves to Mandavya. Seeing him struggle to carry on his religious austerities even though suffering on a stake, the assembled sages were mortified and could hardly bear the sight. Grief-stricken, they said, "O brahmin, we want to hear it directly from you. What sin have you committed to be punished in this terrible way?
That tiger of a sage replied, "It would be wrong to blame others for my suffering. the sage replied to his fellow ascetics. "I do not know what I have done, but surely I and no one else am the cause of my suffering.
Shortly thereafter, the police happened upon the sage Mandavya and were astonished to see that after so many days he was still alive. They told the king exactly what they had seen, and the monarch instantly understood that Mandavya was a true and powerful ascetic. The king and his ministers rushed to the spot, fell at Mandavya's feet, and begged the sage, who was still fixed on the lance, for mercy and forgiveness.
"O best of sages, the king wept, "out of ignorance and illusion I have greatly offended you. Please forgive me. I beg that you not be angry with me.
Thus addressed by the king, Mandavya blessed him with his mercy, and the grateful ruler at once tried to remove the loathsome stake. Unable to pull it out [the 142nd chapter of the first canto of the Garua Pura describes that the stake had gone all the way to the top of the sage's skull], the king broke it off and a portion remained in the sage's body.
Mandavya Muni then resumed his travels, with a portion of the stake still in his body. So determined was he to carry on his religious duties, however, that he began to think of the stake in his body as a flower garland, and by such extraordinary penance he gained promotion to higher planets, which are extremely difficult to reach. After this incident, the sage became known throughout the universe as Ani-mandavya, or "Mandavya-of-the-lance.
Eventually that most learned sage went to see Yamaraja, the lord of death, who is also known as Dharma because he punishes the sinful according to the laws of God. Seeing Dharma sitting in his abode, the powerful Ani-mandavya began to rebuke him. The sage had acquired great power through his extraordinary austerities, and he spoke to Dharma in a threatening voice.
"What evil deed have I committed? Why was I made to suffer such a sinful reaction? Why was I falsely accused and impaled on a lance? I can't understand it. Answer me at once!
Dharma said, "Previously you pierced insects in their tail with a sharp blade of grass. For this act, O ascetic brahmin, you received that reaction.
Animandavya replied, "For a small offense, Yamaraja, you have exacted a very heavy punishment indeed. Therefore, Dharma, for your own sin you will fall among the human beings of earth and take birth from the womb of a dra woman!
Mandavya Muni curses Yamaraj
Because of his offense, Dharma took birth as the noble Vidura from the womb of a dra woman. Completely free of greed and anger and vastly learned in both spiritual and material affairs, he was far-seeing, peaceful, and always devoted to the welfare of the noble Kuru dynasty.