After the Midianites enticed the Israelites to fornicate and worship their false deity (Baal of Peor), Moshe launched a surprise attack and slaughtered all the adults, but the warriors left the children alive, and this angered Moshe. Why did Moshe get so upset? Is there a general principle that says one must kill the male babies?
Yes, It is a general principle in a milchemes-mitzva, a holy war, that one should wipe out the males, since it is presumed that they will grow up and take vengeance for the genocide of their parents. See the tract Toras Hamelech by Rabbi Ginsburg. As for the non-virginal women, it is not clear why they had to be killed. Perhaps it was unclear whether they might be in the early stages of pregnancy.
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.)