But slavery in ancient Israel was a very different sort of institution. It was not based on race. Many slaves were supposed to be freed at the end of seven years, and there was a good bit of movement back and forth between slavery and freedom. Israelite slavery may have been a bad institution, but it was a very different institution from that of American slavery. It was more like the hiring of indentured servants, if one wants an American analogy.
Similar issues arise with the much-debated issue of homosexuality.
We don't know much about what forms homosexuality may have taken place in ancient Israel. In some surrounding cultures, homosexual prostitution was practiced in conjunction with the worship of Baal, and Hebrew law might have condemned such activities because they were homosexual or because they involved prostitution or because they were connected with Baal worship. If a man lies with a male as with a woman, both of them have committed an abomination. It's hard to be sure what the practices were or what about them was judged objectionable.