Why does the Bible endorse slavery?
Hebrew society condoned slavery until about 160BCE. The Exodus and Deuteronomy verses had the goal of making it more humane.
Slavery between Hebrews was more like indentured servitude. If a Hebrew man became too poor to take care of himself and provide for his family, he could sell himself into slavery to a richer man. In exchange for free labour, the master had to feed and provide housing for the slave and his family. Slaves were required to rest on the Sabbath like everyone else. Slaves retained ownership of their own property and control over their own families. A master could beat a disobedient slave, but could not kill him. Killing a slave was a death penalty offense for the master (Exodus 21:12). At the end of six years, in the Year of Jubilee, the master was obligated under Mosaic law to free the slave, set him up with shelter and a means to provide for himself (i.e., cattle, grain and wine). But the slave could also renew his contract for another six years.
"If a fellow Hebrew, man or woman, is sold to you, he shall serve you six years, and in the seventh year you shall set him free. When you set him free, do not let him go empty-handed: Furnish him out of the flock, threshing floor, and vat, with which the Lord your God has blessed you. Bear in mind that you were slaves in the land of Egypt and the Lord your God redeemed you; therefore I enjoin this commandment upon you today. "But should he say to you, 'I do not want to leave you' for he loves you and your household and is happy with you--you shall take an awl and put it through his ear into the door, and he shall become your slave in perpetuity. When you do set him free, do not feel aggrieved; for in the six years he has given you double the service of a hired man. Moreover, the LORD and your God will bless you in all you do."
Slavery between Hebrews and Gentiles was different. Like in other parts of the world, the Hebrews captured slaves in wars with neighboring tribes. Keeping in mind that income at the time came primarily from subsistence farming and herding, and losing a war often meant the loss of land and property, the losers often no longer had any means to make income and faced death from starvation. Enslavement may under certain circumstances may have been the lesser of two evils. Hebrews were also allowed to buy slaves from surrounding tribes who might have become slaves under similar circumstances. There was a Talmudic command that masters attempt to convert Gentile slaves to Judaism and circumcise the males. Those who converted received the same rights as the Hebrew slaves above, but unconverted slaves had fewer rights: they couldn't own property, the rules against abusive treatment didn't apply to them and their service wasn't bound by time limits, so they could be passed on to a master's heirs.
Your male and female slaves are to come from the nations around you; from them you may buy slaves. You may also buy some of the temporary residents living among you and members of their clans born in your country, and they will become your property. You can will them to your children as inherited property and can make them slaves for life, but you must not rule over your fellow Israelites ruthlessly."
Whether God approved of the practice or not is debatable, but the economic circumstances were very different then than they are now. There was no such thing as state welfare payments for the very poor, and people who were dispossessed from land from war or natural disasters often starved to death as they had no means of income. Selling oneself into slavery in exchange for sustenance was thought to be better than being free without sustenance.