I think the reason slavery was in the Bible is because slavery as an economic reality was widely practised up until the mid nineteenth century.. It was a "reality" and as such it was a subject in scripture...
10
But when a famine covered all the land of Chanaan, they went
down into Egypt, and sojourned there, while they were nourished,
and became there a great multitude, so that one could not number
their nation.
11
Therefore the king of Egypt rose up against them, and dealt
subtilly with them, and brought them low with labouring in
brick, and made them slaves.
(Deuterocanonical Apocrypha, Judith)
The Hebrews themselves were enslaved in Egypt.. and they had slaves like most all other ancient peoples.
What was provided in the Bible was what is called the Jubilee.. which stated that every fiftieth year the slaves would go free...and this provided the idea for the abolitionist movement and hope for slaves that someday they could go free!
25:10 And ye shall hallow the fiftieth year, and proclaim liberty throughout all the land unto all the inhabitants thereof: it shall be a jubile unto you; and ye shall return every man unto his possession, and ye shall return every man unto his family.
(King James Bible, Leviticus)
So while there is slavery in the Bible it is ameliorated by such practices as Jubilee.
In the Quran:
"A believer killeth not a believer but by mischance: and whoso killeth a
believer by mischance shall be bound to free a believer from slavery; and the
blood-money shall be paid to the family of the slain, unless they convert it
into alms."
(The Qur'an (Rodwell tr), Sura 4 - Women)
Narrated Ibn 'Umar:
The Prophet said, "Whoever manumits a slave
owned by two masters, should manumit him
completely (not partially) if he is rich after having
its price evaluated."
Volume 3, Book 46, Number 698:
In the Baha'i Writings:
No Industrial Slavery
"In the Book of Aqdas Bahá'u'lláh forbids slavery, and
Abdu'l-Bahá has explained that not only chattel slavery, but
also industrial slavery, is contrary to the law of God. When in
the United States in 1912, He said to the American people: --
Between 1860 and 1865 you did a wonderful thing;
you abolished chattel slavery; but today you must do a
much more wonderful thing: you must abolish industrial
slavery. ...
The solution of economic questions will not be brought
about by array of capital against labor, and labor against
capital, in strife and conflict, but by the voluntary attitude
of goodwill on both sides. Then a real and lasting justness
of conditions will be secured. ..."
(Dr. J.E. Esslemont, Baha'u'llah and the New Era, p. 144)
"He commanded the abolition of both chattel and economic
slavery, and ever since, the progress toward emancipation
has been a ferment in all parts of the world."
(Dr. J.E. Esslemont, Baha'u'llah and the New Era, p. 235)