The OT explicitly regulates and allows slavery and slave trade.
It gives many detailed instructions on how to enslave people, how to make people slaves for life, how you can beat them, how you can buy/sell them, how your kids can inherit them, etc etc.
Why didn't God just outlaw slavery entirely to begin with?
The goal was/is
real change for the better. Not merely stating a Law, but people obeying it.
(Background: Slavery was the normal human practice around the world then. Our modern forms are more diverse and less visible, including subtle forms like intentional underpaying of workers even when a company could pay them more easily and still make nice profits.)
So, the goal is real change, up to the real good:
"So in everything [including pay of workers, kindness to strangers, everything]
, do to others as you would have them do to you."
How to get there?
Israel was given 10 commandments, even half of which can be summarized very simply for us modern Christians as "Love your neighbor as yourself."
And they failed to obey this simple Law during the Exodus journey. Over and over.
And that was only the start of the endless failure to obey the simple 10 commandment Law.
Even after gaining the new land, Israel would break the Law not just occasionally, but over and over and over and over.
The general Law, not being followed, then resulted in what I call
micro regulations (my wording) -- little detailed rules given to make people better able to do what they should,
and what they could in practice, as they were, the people they were.
Baby steps.
Little regulations, like little steps, upward out of the morass of evil and wrong, tiny steps up, one at a time, to lift them out of their wrong and bad ways of treating each other.
Little steps they could actually manage.
And these micro regulations actually help, over time, in a progression, for a larger portion of people.
e.g. -- Instead of 3% obedience, a higher amount happens, like perhaps 15% or 25% even, and later in time higher, like 60%, 80% even, in later generations.
Progression.
Today in 2018,
because only some people follow Matthew 7:12, we have our own secular micro regulations --
Detailed. (Think Kavanaugh; what if Kavanaugh knew the little rules):
Maryland Rape and Sexual Assault Laws - FindLaw
This is our secular law -- little detailed bits -- today in the U.S.
Because only some people obey "In everything, do to others as you would have them do to you".
Do you think we could chuck (discard) our own secular laws, that slow progression in our own secular law, like the Maryland Rape and Sexual Assault Laws?
Seems the American experience is that we
need baby steps upward over time. In America. Today.
Just like in the Old Testament.