Some argue that it was immoral for God to give the Midianite virgins to the Israelites in Numbers 31:17-18. However, there are several responses that answer this alleged problem in the Bible.
17 Now therefore, kill every male among the little ones, and kill every woman who has known man by lying with him. 18 But all the young girls who have not known man by lying with him keep alive for yourselves.Numbers 31:17-18
It was actually merciful for the Israelites to spare the Midianite virgins because the alternative was certain death. Without the rest of their tribe, these Midianite virgins would have been left alone to die if the Israelites did not take them into the Israelite nation.
It was not wrong for the Israelite nation to enter into war with the Midianite nation and to kill the people of that nation because:
Some might argue that the Midianite virgins may not have seen the Israelite nation as being merciful. However, it can be strongly argued that it is better to live than to die, and the simple reality is that many difficult things happen in the context of war.
There are some foundational principles that apply to all alleged and apparent contradictions in the Bible. To read more, see Bible Difficulties: Foundational Principles.
To read more answers to alleged and apparent contradictions in the Bible, see “Contradictions” in the Bible Answered.
These books are also excellent resources: