The reason is quite clear in the text Spock. Because the virgins did not take part in the defiling of Israel at Peor. We've already been through the capital punishment discussion. No test. If the man were to have sex with a women who was not his wife he was either obliged to marry and care and provide for her or if she was already betrothed or married he was to be punished. Again, I don't agree with what they did. I'm just pointing out that you claim that boys who were raped were killed is not true.