Here are a few relevant paragraphs from a book by Lewis on Slavery. It gives a better flavor of the historical context in which slavery existed in the Middle East. Slavery still exists today, and the context is quite different.
Bernard Lewis. Race and Slavery in the Middle East
Oxford Univ Press 1994
The Qur’an, like the Old and the New Testaments, assumes the existence of slavery. It regulates the practice of the institution and thus implicitly accepts it. The Prophet Muhammad and those of his Companions who could afford it themselves owned slaves; some of them acquired more by conquest. But Qur’anic legislation, subsequently confirmed and elaborated in the Holy Law, brought two major changes to ancient slavery which were to have far-reaching effects. One of these was the presumption of freedom; the other, the ban on the enslavement of free persons except in strictly defined circumstances .
The Qur’an was promulgated in Mecca and Medina in the seventh century, and the background against which Qur’anic legislation must be seen is ancient Arabia. The Arabs practiced a form of slavery, similar to that which existed in other parts of the ancient world. The Qur’an accepts the institution, though it may be noted that the word 'abd (slave) is rarely used, being more commonly replaced by some periphrasis such as ma malakat aymanukum, “that which your right hands own.” The Qur’an recognizes the basic inequality between master and slave and the rights of the former over the latter (XVI:71; XXX:28). It also recognizes concubinage (IV:3; XXIII:6; XXXIII:50-52; LXX:30). It urges, without actually commanding, kindness to the slave (IV:36; IX:60; XXIV:58) and recommends, without requiring, his liberation by purchase or manumission. The freeing of slaves is recommended both for the expiation of sins (IV:92; V:92; LVIII:3) and as an act of simple benevolence (II:177; XXIV:33; XC:13). It exhorts masters to allow slaves to earn or purchase their own freedom. An important change from pagan, though not from Jewish or Christian, practices is that in the strictly religious sense, the believing slave is now the brother of the freeman in Islam and before God, and the superior of the free pagan or idolator (II:221). This point is emphasized and elaborated in innumerable hadlths (traditions), in which the Prophet is quoted as urging considerate and sometimes even equal treatment for slaves, denouncing cruelty, harshness, or even discourtesy, recommending the liberation of slaves, and reminding the Muslims that his apostolate was to free and slave alike.
Though slavery was maintained, the Islamic dispensation enormously improved the position of the Arabian slave, who was now no longer merely a chattel but was also a human being with a certain religious and hence a social status and with certain quasi-legal rights. The early caliphs who ruled the Islamic community after the death of the Prophet also introduced some further reforms of a humanitarian tendency. The enslavement of free Muslims was soon discouraged and eventually prohibited. It was made unlawful for a freeman to sell himself or his children into slavery, and it was no longer permitted for freemen to be enslaved for either debt or crime, as was usual in the Roman world and, despite attempts at reform, in parts of Christian Europe until at least the sixteenth century. It became a fundamental principle of Islamic jurisprudence that the natural condition, and therefore the presumed status, of mankind was freedom, just as the basic rule concerning actions is permittedness: what is not expressly forbidden is permitted; whoever is not known to be a slave is free. This rule was not always strictly observed. Rebels and heretics were sometimes denounced as infidels or, worse, apostates, and reduced to slavery, as were the victims of some Muslim rulers in Africa, who proclaimed jihad against their neighbors, without looking closely at their religious beliefs, so as to provide legal cover for their enslavement. But by and large, and certainly in the central lands of Islam, under regimes of high civilization, the rule was honored, and free subjects of the state, Muslim and non-Muslim alike, were protected from unlawful enslavement.
Since all human beings were naturally free, slavery could only arise from two circumstances: (1) being born to slave parents or (2) being captured in war. The latter was soon restricted to infidels captured in a jihad.
These reforms seriously limited the supply of new slaves. Abandoned and unclaimed children could no longer be adopted as slaves, as was a common practice in antiquity, and free persons could no longer be enslaved. Under Islamic law, the slave population could only be recruited, in addition to birth and capture, by importation, the last either by purchase or in the form of tribute from beyond the Islamic frontiers. In the early days of rapid conquest and expansion, the holy war brought a plentiful supply of new slaves, but as the frontiers were gradually stabilized, this supply dwindled to a mere trickle. Most wars were now conducted against organized armies, like those of the Byzantines or other Christian states, and with them prisoners of war were commonly ransomed or exchanged. Within the Islamic frontiers, Islam spread rapidly among the populations of the newly acquired territories, and even those who remained faithful to their old religions and lived as protected persons (dhimmis) under Muslim rule could not, if free, be legally enslaved unless they had violated the terms of the dhimma, the contract governing their status, as for example by rebelling against Muslim rule or helping the enemies of the Muslim state or, according to some authorities, by withholding pa’yment of the Kharaj or the Jizya, the taxes due from dhimmls to the Muslim state.
In the Islamic empire, the humanitarian tendency of the Qur’an and the early caliphs was to some extent counteracted by other influences. Notable among these was the practice of the various conquered peoples and countries which the Muslims encountered after their expansion, especially in provinces previously under Roman law. This law, even in its Christianized form, was still very harsh in its treatment of slaves. Perhaps equally important was the huge increase in the slave population resulting first from the conquests themselves, and then from the organization of a great network of importation. These led to a fall in the cash value and hence the human value of slaves, and to a general adoption of a harsher tone and severer rules. But even after this stiffening of attitudes and laws, Islamic practice still represented a vast improvement on that inherited from antiquity, from Rome, and from Byzantium.
Slaves were excluded from religious functions or from any office involving jurisdiction over others. Their testimony was not admitted at judicial proceedings. In penal law, the penalty for an offense against a person, a fine or bloodwit, was, for a slave, half of that for a freeman. While maltreatment was deplored, there was no fixed shari’a penalty. In what might be called civil matters, the slave was a chattel with no legal powers or rights whatsoever. He could not enter into a contract, hold property, or inherit. If he incurred a fine, his owner was responsible. He was, however, distinctly better off, in the matter of rights, than a Greek or Roman slave, since Islamic jurists, and not only philosophers and moralists, took account of humanitarian considerations. They laid down, for example, that a master must give his slave medical attention when required, must give him adequate upkeep, and must support him in his old age. If a master defaulted on these and other obligations to his slave, the qadi could compel him to fulfill them or else either to sell or to emancipate the slave. The master was forbidden to overwork his slave, and if he did so to the point of cruelty, he was liable to a penalty which was, however, discretionary and not prescribed by law. A slave could enter into a contract to earn his freedom, in which case his master had no obliation to pay for his upkeep. While in theory the slave could not own property, he could be granted certain rights of ownership for which he paid a fixed sum to his master.
A slave could marry, but only by consent of the master. Theoretically, a male slave could marry a free woman, but this was discouraged and in practice prohibited. A master could not marry his own slave woman unless he first freed her. Islamic law provides a number of ways in which a slave could be set free. One was manumission, accomplished by a formal declaration on the part of the master and recorded in a certificate which was given to the liberated slave. The manumission of a slave included the offspring of that slave, and the jurists specify that if there is any uncertainty about an act of manumission, the slave has the benefit of the doubt. Another method is a written agreement by which the master grants liberty in return for a fixed sum. Once such an agreement has been concluded, the master no longer has the right to dispose of his slave, whether by sale or gift. The slave is still subject to certain legal disabilities, but in most respects is virtually free. Such an agreement, once entered into, may be terminated by the slave but not by the master. Children born to the slave after the entry into force of the contract are born free. The master may bind himself to liberate a slave at some specified future time. He may also bind his heirs to liberate a slave after his death. The law schools differ somewhat on the rules regarding this kind of liberation.