Let us look at the verses in question:
Numbers 31:7, 17-18 “They fought against Midian, as the LORD commanded Moses, and killed every man…….Now kill all the boys [innocent kids]. And kill every woman who has slept with a man, but save for yourselves every girl who has never slept with a man.“
You can read the entire story of the Israelites and the Midianites in the short chapter of Numbers 31 for more details.
Now, few points to mention here:
1- All of the males (infants, children, grown men, and elderly) were killed.
2- Every woman who was not a virgin was also killed.
3- Every girl who was a virgin was saved as a spoil of war.
First of all, we need to picture the whole scenario here so we can get a better understanding of what exactly went on. After the Israelite’s victory over the Midianites, and after the capturing of all of their lands and people, the thousands of the remaining Midianite people were gathered at once. The remaining men and all male children were taken and slaughtered. The women were all lined up for checking.
Now how do you think they were able to tell who is a virgin from a non-virgin, especially that all of the men seem to have been killed first. Certainly a newly wed girl who didn’t have children yet could easily deny that she was ever touched by a man. Do you think the Israelites just questioned the women and the girls and took their words at face value? Of course not. From all of the evidence that we have in this article’s sections above, and from the clear picture of what took place from events in the Numbers 31:7, 17-18 verses, there is no question in my mind that:
1- Every single mother was slaughtered along with the men.
2- Every single “young” girl was literally checked by inserting a finger(s) into her vagina to tell whether she was a virgin or not. Perhaps most likely also, men did the checking. As we see in the next sub-section, they even inserted their penises into 3-year old girls!!
3-year old girls were literally raped!
We also need to know that according to the Jewish Talmud’s elaboration on the historical events that took place in the Numbers 31, 17-18, Moses and his men literally inserted their penises into girls who were as young as 3 years old (three years old). Here is the proof:
Sometimes one has to read a passage twice to believe what has been written in the Sacred Books of Judaism: what has been decreed the way to a holy life by the “sages of blessed memory… whose words are the natural sounds of Judaism” :
Said Rabbi Joseph, “Come and take note: A girl three years and one day old is betrothed by intercourse. And if a Levir has had intercourse with her, he has acquired her. And one can be liable on her account because of the law prohibiting intercourse with a married woman. And she imparts uncleanness to him who has intercourse with her when she is menstruating, to convey uncleanness to the lower as to the upper layer [of what lies beneath]. If she was married to a priest, she may eat food in the status of priestly rations. If one of those who are unfit for marriage with her had intercourse with her, he has rendered her unfit to marry into the priesthood. If any of those who are forbidden in the Torah to have intercourse with her had intercourse with her, he is put to death on her account, but she is free of responsibility [M.Nid. 5:4].
Sanhedrin 7/55B 
R. Nahman bar Isaac said. “They made the decree that a gentile child should be deemed unclean with the flux uncleanness [described at Lev.15], so that an Israelite child should not hang around with him and commit pederasty [as he does].”
For said R. Zira, “I had much anguish with R. Assi, and R. Assi with R. Yohanan, and R. Yohanan with R. Yannai, and R. Yannai with R. Nathan b. Amram, and R. Nathan b. Amram with Rabbi [on this matter]: ‘From what age is a gentile child deemed unclean with the flux uncleanness [described at Lev.15]’? And he said to me, ‘On the day on which he is born.’ But when I came to R. Hiyya, he said to me, ‘From the age of nine years and one day.’ And when I came and laid the matter before Rabbi, he said to me, ‘Discard my reply and adopt that of R. Hiyya, who declared, “From what age is a gentile child deemed unclean with the flux uncleanness [described at Lev.15]? From the age of nine years and one day.”‘
[37A] Since he is then suitable for having sexual relations, he also is deemed unclean with the flux uncleanness [of Lev.15].”
Said Rabina, “Therefore a gentile girl who is three years and one day old, since she is then suitable to have sexual relations, also imparts uncleanness of the flux variety.”
That is self-evident!
Abodah Zarah 36B-37A 
The basis for these rulings is the following Mishnaic passage of Tractate Niddah (filth):
A girl three years and one day old is betrothed by intercourse. “A girl three years old may be betrothed through an act of sexual intercourse,“the words of R. Meir. And sages say, “Three years and one day old.”
And if a Levir has had intercourse with her, he has acquired her. And they are liable on her account because of the law prohibiting intercourse with a married woman. And she imparts uncleanness to him who has intercourse with her when she is menstruating to convey uncleanness to the lower as to the upper layer. If she was married to a priest, she eats heave offering. If one of those who are unfit for marriage has intercourse with her, he has rendered her unfit to marry into the priesthood. If one of all those who are forbidden in the Torah to have intercourse with her did so, they are put to death on her account. But she is free of responsibility.
If she is younger than that age, intercourse with her is like putting a finger in the eye.
(Mishnah Niddah 5:4) 
Thus, one “of the many important issues worked out in the Mishnah concerns proper conduct with women,”  and the “entire society of Judaism – that is, the community formed by the Torah – found in the Talmud those modes of thought and inquiry, those media of order and value, that guided the formation of public affairs and private life as well.” 
While it is reassuring to see there was at least some limit as to what the sages would declare holy and moral, this ruling had severe implications on the interpretation of other topics as well. The Tannaïtic Midrash Sifre to Numbers in §157 comments on the above quoted commandment of Moses to kill the Midianite women as well as the male children:
“Now therefore, kill every male among the little ones, and kill every woman that has known a man by sleeping with him.(Num 31:17).
[This] refers to her who has slept with a man as well as her who is suitable for intercourse, even when she has not slept with a man…
But all the young girls who have not known a man by sleeping with him, keep alive for yourselves. From here R. Shimon b. Yohai used to say: a Proselyte girl who became a proselyte in the age of less than three years and one day, is rendered fit to marry into the priesthood.” 
According to the Tannaïte Rabbis, Moses therefore had ordered the Israelites to kill all women older than three years and a day, because they were “suitable for having sexual relations.” 
 Ibid., vol.XXI.A-D, Tractate Bava Mesia, Atlanta: Scholars Press 1990, p.ix-x.
 Ibid., vol.XXIII.B, Tractate Sanhedrin 1984, 150. See also vol.XIX.A, Tractate Qiddushin 10a-b, 1992, 33. “Menstruating” here of course refers to the ritual “flux uncleanness” described in Lev.15.
 Ibid., vol.XXV.A, Tractate Abodah Zarah, 1991, 168. Emphasis original.
 J. Neusner, The Talmud of Babylonia. A complete outline, Part IV. The Division of Holy Things. B. Number 37. 1995, 704.
 Neusner 1993, 41.
 Neusner 1995, 7.
 Kuhn 1959, §157, 652f. My translation. In general, proselytes are not allowed to marry into the priesthood.
 Ibid., §157, footnote 86, 653.