The passages from the Old Testament where most or all of a group of people were wiped out are passages that Muslims love to point to. Their reason is not well hidden – it is to justify the deeds that were done by Muhammad and the early Muslims as they conquered the tribes around Arabia and beyond. The two have different motivations. The Israelites were told to wipe out some tribes in judgement from God for their evil behaviour. The Muslims made no distinction between the tribes that they conquered regarding their behaviour – it was about financial gain and taking slaves. The God of the Bible is well within his rights to judge nations that commit acts of evil. In fact we are told that God holds back from judging nations and individuals because “The Lord is not slow in keeping his promise, as some understand slowness. Instead he is patient with you, not wanting anyone to perish, but everyone to come to repentance.” (2 Peter 3:9). We also read that God promises Abraham that his descendants will return to the land to take it as theirs but not yet because the people living there had not yet become as evil as they would later, “In the fourth generation your descendants will come back here, for the sin of the Amorites has not yet reached its full measure.” (Genesis 15:16). What God was saying was that the Amorites would lose the land to the Israelites because of their evil practices but not yet because they had not sunk to their lowest state as yet. God is merciful but when the time comes for judgement, he will act impartially. This is a fact that people have to recognise before it is too late.
The Midianites from Numbers 31 was a special case. The Jews were getting close to entering Canaan but they came up against King Balak who saw what the Jews had done to the Amorites and was afraid. So he hired Balaam to come and curse the Jews so that he could defeat them. Famously, Balaam was held back by God from cursing the Jews but he did get the Midianites to entice some of the Jewish males to idolatry by getting the woman to seduce them and to get them to join them at the sacrifices to their god Baal. This led to judgement from God and 24,000 of the Jews were slain by God.
Moses sent 12,000 soldiers to destroy the Midianites but foolishly they kept all the females alive. Moses was not pleased with them for this and said “Have you allowed all the women to live? They were the ones who followed Balaam’s advice and enticed the Israelites to be unfaithful to the Lord in the Peor incident, so that a plague struck the Lord’s people.” (Numbers 31:16).
So why did Moses say to keep the young virgins alive but not the older women? The older women were likely involved in the earlier deception with Jewish men but the young virgins were innocent of this crime, so God in his mercy was prepared to spare them. The virgins would not have been a likely source of temptation unlike the older women because they wouldn’t have become desensitised to that life style. Over time the virgins would have married the men of Israel or been taken into families as slaves and been assimilated into the Jewish culture.
What would have not happened, is that they would have been raped or mistreated. This was strictly not allowed in the Jewish culture. This is not something that Islam can say.