The Torah allowed the concept of slavery but restricted its practices with the intention of teaching the wrongs within the system. The goal of the Torah was to end slavery. Other examples are the sacrifices, polygamy, and much more. Yet it allows the license to these primitive laws because the ancient Israelites lived in a time where slavery was customary.
The Rambam teaches that although G-d can change human nature, He choices not to do so. Thus G-d has to allow certain rules in the Torah that seem harsh even today. The legislation of slavery, sacrifices, and capital punishment served a better interest for the public, even though a careful reading and analysis will show that the Torah never condoned these practices. For example, the Torah’s legislation of a slave’s life made his life much easier than his contemporaries in other countries. So much so, that the rabbis later said, “he who acquires a slave secures a master over himself,” for in Hebrew the correct translation is “servant.”
Similarly, the sacrificial system was restricted and minimizing only to certain animals and the abhorrence of capital punishment made its infliction impossible. The same can be applied to stoning misbehaving children in Deuteronomy 21:18-21, not offering peace to the Canaanites in Deuteronomy 20:16-18, the laws of a condemned city in Deuteronomy 13:13-19, and the law of a captive woman and Deuteronomy 21:10-14.
For example, the law for an “eye for an eye” was always met with compensation as restricted in the Torah and Oral law in the Talmud(s). The injury was not met with physical damage in any way. The anti-Semites that use this phrase, like slavery and many others, to justify revenge which is forbidden in (Leviticus19:18) shows that these laws were never implemented.
Sources: The parashah found in Exodus 21:19 and Targum Onkelos understands that and eye for an eye is met with payment. See also Midrash Mekhilta and the Babylonian Talmud, Bava Kamma 85a. See Talmud (ibid.). Also Shakespeare’s The Merchant of Venice (4:1) makes is abundantly clear that the law is not physical damage.