Plotz calls it the "most hideous war crime in a Bible filled with them." And he's right about that. It is simply impossible to read this and still believe that it was inspired by a kind and loving God. Here's a brief summary, but if you haven't read the entire story, be sure to do so. (Numbers 31:1-35)
God tells Moses to "avenge the children of Israel of the Midianites." So "they warred against the Midianites, as the LORD commanded Moses; and they slew all the males," taking the women and children captive.
But when the officers returned from the battle, Moses was angry with them, saying, "Have ye saved all the women alive?" So he tells them to
...kill every male among the little ones, and kill every woman that hath known man by lying with him. But all the women children, that have not known a man by lying with him, keep alive for yourselves. (Numbers 31:17-18)
The soldiers do as they were told, killing all the women and children except for the virgins, of which there were 32,000. And since there must have been at least twice as many men, non-virgin women, and young boys, I used 90,000 for the Midianite massacre in the revised death toll.