While all of these "Divine" commandments are truly disgusting, and appalling in nature, the answer to the OPs question is simple.
The younger woman of that day, and in that part of the world, were known to be virgins by 2 simple "facts". One, they wore special robes/clothing that once they began menstruation, tradition compelled them to wear. This denoted that they were now ready for child bearing, and untouched sexually.
The second thing, was that they were simply unmarried. Any girl, within the usual early child bearing age, who was unmarried, and wore the robes/garments that identified them as able to bare child, were the virgins we are speaking of.
As the enemy nation was conquered, all were put to the sword, and all these young girls wearing these robes/garments, would have been rounded up, and held in captivity, until the conquering was done. At this point they were divided up, and chosen/picked, with the officers and higher ups in the military given first "pick", and then each lower ranking soldier picking until none were left.
Basically treated as cattle, or slaves, with no rights or say. Their duty was now to their new "husband". What a "loving" arrangement by Jah. Sounds like a bunch of Bulls#$t to me. All it was, was a listing of the "rules of war", for the nation of Israel, who pretended, in their writings, that they were some powerful all conquering military power. When in reality, they were a nomadic tribe, that occasionally defeated and plundered some even smaller nomadic groups they encountered.
On another note, it used to drive me crazy, back when i was younger, and i would question the barbarity of MANY of the acts in the bible, especially the Old testament, and i would be told that it was warranted back then because of the time period. That never made sense to me, though. Why would the chosen nation of the Almighty, One true God, need to have HIS nation lower themselves to the "barbaric" gentile nations around them, instead of leading by example, and ushering in a new way of doing things peacefully and amicably with all those around them.
Doesnt make sense, it just made Jah another pagan God, acting like every other God around him.