hmmm, there was no “slavery” in the Israely culture, the law allowed a man or woman to become servant but that did not mean that they had become the “property” of someone.
In fact that same law was very explicit as to the way someone had to treat their servants.
You can read this when in some passages poeple preferred to be someone’s servant rather than live by their own devises.
Now the midianites were pagans who used sex to corrupt and conquer the neighboring nations, you can read about this since because of them, thousands of Israel’s men were put to death after having been led astray to worship the god of the midianites by their women.
What other means did Moses have to ensure his people did not fall again to the alluring temptations?
GOD is love amen to this, that however does not mean HE is also a fool.