He (Yamaraja) wanted to preach the glories of the Lord, and therefore by the will of the Lord he was cursed by Manduka Muni to come into the world in the incarnation of Vidura and work very hard as a great devotee
SB Canto 1
As long as Vidura played the part of a śūdra, being cursed by Maṇḍūka Muni, Aryamā officiated at the post of Yamarāja to punish those who committed sinful acts.
Vidura, born in the womb of a śūdra woman, was forbidden even to be a party of royal heritage along with his brothers Dhṛtarāṣṭra and Pāṇḍu. Then how could he occupy the post of a preacher to instruct such learned kings and kṣatriyas as Dhṛtarāṣṭra and Mahārāja Yudhiṣṭhira? The first answer is that even though it is accepted that he was a śūdra by birth, because he renounced the world for spiritual enlightenment by the authority of Ṛṣi Maitreya and was thoroughly educated by him in transcendental knowledge, he was quite competent to occupy the post of an ācārya, or spiritual preceptor. According to Śrī Caitanya Mahāprabhu, anyone who is conversant in the transcendental knowledge, or the science of Godhead, be he a brāhmaṇa or a śūdra, a householder or a sannyāsī, is eligible to become a spiritual master. Even in the ordinary moral codes (maintained by Cāṇakya Paṇḍita, the great politician and moralist) there is no harm in taking lessons from a person who may be by birth less than a śūdra. This is one part of the answer. The other is that Vidura was not actually a śūdra. He was to play the part of a so-called śūdra for one hundred years, being cursed by Maṇḍūka Muni. He was the incarnation of Yamarāja, one of the twelve mahājanas, on the level with such exalted personalities as Brahmā, Nārada, Śiva, Kapila, Bhīṣma, Prahlāda, etc. Being a mahājana, it is the duty of Yamarāja to preach the cult of devotion to the people of the world, as Nārada, Brahmā, and other mahājanas do. But Yamarāja is always busy in his plutonic kingdom punishing the doers of sinful acts. Yamarāja is deputed by the Lord to a particular planet, some hundreds of thousands of miles away from the planet of earth, to take away the corrupt souls after death and convict them in accordance with their respective sinful activities. Thus Yamarāja has very little time to take leave from his responsible office of punishing the wrongdoers. There are more wrongdoers than righteous men. Therefore Yamarāja has to do more work than other demigods who are also authorized agents of the Supreme Lord. But he wanted to preach the glories of the Lord, and therefore by the will of the Lord he was cursed by Maṇḍūka Muni to come into the world in the incarnation of Vidura and work very hard as a great devotee. Such a devotee is neither a śūdra nor a brāhmaṇa. He is transcendental to such divisions of mundane society, just as the Personality of Godhead assumes His incarnation as a hog, but He is neither a hog nor a Brahmā. He is above all mundane creatures. The Lord and His different authorized devotees sometimes have to play the role of many lower creatures to claim the conditioned souls, but both the Lord and His pure devotees are always in the transcendental position. When Yamarāja thus incarnated himself as Vidura, his post was officiated by Aryamā, one of the many sons of Kaśyapa and Aditi. The Ādityas are sons of Aditi, and there are twelve Ādityas. Aryamā is one of the twelve Ādityas, and therefore it was quite possible for him to take charge of the office of Yamarāja during his one hundred years' absence in the form of Vidura. The conclusion is that Vidura was never a śūdra, but was greater than the purest type of brāhmaṇa.