First, it would be helpful to consider why God allowed Hebrews to enslave other Hebrews. Though they had all been slaves in Egypt and were now set free, Moses permitted a sort of voluntary slavery to continue. Individuals could sell their services for up to six years to repay debts or make restitution. Hebrew slaves were regarded more as hired hands. The seventh year, their debts were canceled, and they received their freedom.
Second, with regard to why God would make provision for a husband and wife not to leave together when the husband was no longer a slave. This would make more sense to us if we could see through the lens of their culture. Their customs required a man to “purchase” a wife by paying a bride-price to her father. If a slave owner purchased a bride for his servant, however, she technically belonged to the one who paid the price. This policy seems harsh, but it was softened by other provisions (see Exodus 21:8,11,26-27).
–The Quest Study Bible