Slavery has been a fact of life for thousands of years.
That doesn’t mean God approved of slavery. Paul made this clearer in his letter to the Galatians, telling them that everyone is equal before God, and in instructing Philemon to treat the escaped slave Onesimus as a brother.
The evidence in the Bible suggests God put up with slavery, but His campaign to end it started early.
The reasoning is in God’s introduction to the ten commandments:
20:2 I am the Lord your God, who rescued you from the land of Egypt, the place of your slavery.
Kidnapping people—taking them against their will— was banned, regardless of their race. It means that Israelites would have been banned from the front end of the slave trade:
21:16 “Kidnappers must be put to death, whether they are caught in possession of their victims or have already sold them as slaves.
If all the world were subject to these regulations, and people complied with them, this clause alone would have stopped slavetrading.
Remember the Ishmaelite slave traders who bought Joseph to sell him to the Egyptians? They would have had to find something other than people to sell.
Israelites who found themselves in slavery—often as a way of paying of debts— were more like indentured labourers than what we would imagine oppressed slaves to be like today.
The guidelines were strict for their day, for example:
21:2 If you buy a Hebrew slave, he may serve for no more than six years. Set him free in the seventh year, and he will owe you nothing for his freedom.
This applied equally to women as to men. Female slaves could also be sourced from fathers selling their daughters, with a strong suggestion that this was under a presumption of future marriage. This gave them more rights than would have been usual for the day.
There was a strong incentive to not beat slaves: knocking out a tooth was enough to set the slave free. This was well before modern dental treatment, and so it might be more restrictive then we would first assume. If the slave died, the owner would be judged under the murder regulations.
Slaves also enjoyed the Sabbath:
23:12 You have six days each week for your ordinary work, but on the seventh day you must stop working. This gives your ox and your donkey a chance to rest. It also allows your slaves and the foreigners living among you to be refreshed.