Slavery in the Bible wasn’t immoral. The immoral thing would be not to have it, as many people are helpless without the right organization. It was a strategy to help keep people fed, so they couldn’t starve and was completely voluntary.
Not to mention they didn’t have heavy machinery or abundant moneys so they needed a way to do industrial scale work and compensate it fairly, and that was their way.