Moshe's command was to spare the maidens., (Bamidbar 31:18) but not the males. Since Moshe was an accepted prophet, there is a positive mitzvah to heed his words.
The Gemara also brings up the idea (although it is not accepted) that a female convert 3 years and younger can marry a Kohen. Perhaps that has something to do with it?
And our King David left no man, woman, or child alive on various occasions. This may have been in a similar vein to the precedent set by Moshe, (e.g. everyone dies except the maidens/yafos toar etc.)