When the small army came back from their attack on the Midianites, Moses met them and saw the captives, booty, and spoil. Moses showed his displeasure with the fact that they kept all the women alive.
Numbers 31:16–17 (NKJV)
16 Look, these women caused the children of Israel, through the counsel of Balaam, to trespass against the Lord in the incident of Peor, and there was a plague among the congregation of the Lord. 17 Now therefore, kill every male among the little ones, and kill every woman who has known a man intimately.
The fact that they cleansed themselves of sin and sinful things, and then attacked Midian to destroy them, was just another part of the process of cleansing prior to entering the promised land. Then, they brought home women who had most likely served false gods and led others to the sin of idolatry. In order to prevent this from happening again, the mature women would be killed.
The priest, Eleazar, instructed them to purify the spoils by passing anything that would not burn up to be passed through the fire, and everything that could burn up be washed in water, to purify it all. God was truly insistent that everything that entered the promised land be free from impurities and sin. Again, God wants His people to be sanctified and holy before entering into the place of Promise and calling. God offers sanctification to all who desire to grow in the Lord. God longs for a deeper relationship with His people. Walk deeper, pray meaningfully, live in the Word, walk in the Spirit. God draws near to those who draw near to Him.