I think God allowed slavery for the same reason that he allowed divorce: because, as Jesus said, the Israelites’ hearts were hard. However, slavery back then wasn’t the same as the enslavement of Blacks by American whites. For example, God says that anyone who kidnaps a man must be put to death (Exodus 21:16). Thus, slavery, as it was used in the United States, would be breaking the Mosaic law.
Furthermore, God often says throughout the Pentateuch to “Remember that you were slaves in Egypt and the Lord your God redeemed you” (Deuteronomy 15:15). Basically, God is saying that you guys were slaves and you remember how being treated like dirt sucked. Therefore, treat your own slaves well because you know how it feels to be mistreated.