At the time of Islam’s revelation, slavery was a prevalent phenomenon, even in empires such as Rome. Since the abolishment of such a widespread and deep rooted phenomenon was not possible all at once, Islam opened various other routes towards its gradual abolishment. From one angle, Islam reduced the ways that people could be taken as slaves, and from the other angle, it made the freeing of slaves an Islamic institution
At the time of Islam’s revelation, slavery was a prevalent phenomenon, even in empires such as Rome. Since the abolishment of such a widespread and deep rooted phenomenon was not possible all at once, Islam opened various other routes towards its gradual abolishment. From one angle, Islam reduced the ways that people could be taken as slaves, and from the other angle, it made the freeing of slaves an Islamic institution. For example, slaves were freed as expiation for various sins and offenses, as well as for abandoning various obligatory religious duties. Through these steps, Islam reduced the means for the taking of new slaves, and opened the door widely for their release. From a third angle, the Prophet of Islam (saww) recommended to the Muslims that they should treat slaves with humanity (much like they would treat their own families), and ordered that the slaves be given the same foods that the owners themselves would eat, and clothes which they themselves would wear.
Even beyond these points, the releasing of slaves was given such value, worth, and religious virtue that in various traditions, many of the pious actions are equated with the freeing of slaves in terms of the amount of reward that one would receive for them; Muslims were highly encouraged to engage in the act of releasing slaves.
When researching the life of Imam Sajjad (‘a), accounts of the freeing of slaves are found quite abundantly. Yet the scope and extent of his actions are so vast, that the simple reward for freeing them cannot be seen as the sole impetus; it seems that the 4th Imam (‘a) had much higher goals than this. Attention to this matter shows that the Imam (‘a) had goals along the lines of training and educating the slaves. History shows that he would buy them, and then spend a period of time training and educating them. Later, after they were freed, they would go in to the society as models of exemplary human beings and engage in the training and teaching of others. Even after their release, they would still keep their connection with the Imam (‘a) and this link would not be discontinued.
‘Ali ibn Ṭāwūs, in the midst of the month of Ramadan, wrote: ‘Ali ibn Husayn (‘a) would release 20 slaves on the last night of the month of Ramadan, and he would say: Every night in the month of Ramadan, during the time of completing the fast, God releases 70,000 of the people of hell from the torment of its flames; during the last night, he releases a number equal to all the other nights of Ramadan combined. I would like that my Lord sees that I have released my slaves in this world, so that he will free me from the fire of hell on the Day of Judgment.
Imam Sajjad (‘a) would never keep a slave for longer than 1 year. Whenever he would bring a slave at the beginning or middle of the year, he would free them on the night of ‘Īd al-Fitr, and during the next year he would bring another individual in place of them, and again, free them in the month of Ramadan; this continued until the very end of his life.
The Imam (‘a) would buy black slaves, even though he had no need for them, and he would bring them to the Ḥajj pilgrimage. During the Ḥajj rites, as he was departing towards Mash’ar, he would free them and give them money.
According to one of the writers: Whenever the slaves would become aware of this, they would find a way to free themselves from their slavery under the nobles and aristocrats and go in to the service of Imam Zayn al-’Abidīn (‘a). Time passed and Imam Sajjad (‘a) was still engaged in freeing slaves. Every year, every month, and every day, during various occasions, he would repeat this action until there existed a large group of slaves and servants who had been freed by him in the city of Medina.
It is evident that the Imam (‘a) had in reality created an establishment for training and educating others. He would buy slaves, keep them under his supervision for a period of time, and then engage in training and educating them. When the time arrived for freeing them, each one of them was an example for other people in the society. After they were freed, they would not cut off their spiritual connection with the Imam (‘a), and they would in turn engage in training and educating other people in the society. This program of the Imam (‘a) is a truly fascinating and captivating one, and is worthy of contemplation and further research. 
 Refer to: Irajī, Muhammad Sadiq, Slavery in Islam, Tehran University.  Iqbāl al-'a'māl, Second Edition, Tehran, Dār al-Kutub al-Islāmīyah, 1390 Hijrī Qamarī, p. 261.  Sayyid al-'Ahl, 'Abd al-Aziz, The Life of Zayn al-'Abidīn (a), translated by Ḥusayn Wujdānī, Third Print, Tehran, New Month Magazine Publications, p. 55.  In preparing this section, the following book was used: The 4th Imam (a) as the Guardian of the Revolution of Karbala, written by 'Alī Akbar Ḥasanī.  Taken from the text: Sīrah Pīshvāyān, Mahdī Pīshvāī, Mu'asasah Imam Sadiq (Ýa), Qum, 1390 Hijrī Shamsī, 23rd Edition, p. 305.