But all the women children, that have not known a man by lying with him, keep alive for yourselves. (Numbers 31:18)
For a law that came later, the enactment of which may have reflected the capture of these women, see
Deut. 21:10-14.
Since they were young and impressionable there was the possibility of their being weaned from idolatry and its unclean practices.