In Bamidbar 25:16-18, Hashem commands Moshe to take revenge on Midian for having caused the Jews to sin at Shittim, discussed at the beginning of the chapter. Yet v. 1 seems to indicate that the Jews sinned with Moav as well:
וישב ישראל בשטים ויחל העם לזנות אל בנות מואב
And Yisrael dwelled in Shittim, and the people debased themselves to commit harlotry with the daughters of Moav.
So, if Moav was involved with the incident at Shittim as well, why was the command to attack directed only at Midian?
In the context of consoling R' Shmuel bar Yehudah over the loss of his daughter, Ulla makes the following exposition (Bava Kamma 38a-b, in part quoted by Rashi in his commentary to Bamidbar 25:17 and 31:2):
״ויאמר ה׳ אלי אל תצר את מואב ואל תתגר בם מלחמה״ (דברים ב:ט). וכי מה עלה על דעתו של משה לעשות מלחמה שלא ברשות? אלא נשא משה קל וחומר בעצמו. אמר: ומה מדינים שלא באו אלא לעזור את מואב, אמרה תורה, ״צרור את המדינים והכיתם אותם״ (במדבר כה:יז), מואבים עצמן לא כל שכן? אמר לו הקדוש ברוך הוא: לא כשעלתה על דעתך עלתה על דעתי. שתי פרידות טובות יש לי להוציא מהן: רות המואביה ונעמה העמונית.
"And Hashem said to [Moshe], don't distress Moav, and don't incite war against them" (Devarim 2:9). What would have arisen on Moshe's mind to do war with them without permission? Rather, Moshe reasoned to himself with an a fortiori argument. He said: If regarding the Midianim, who only came to help Moav, the Torah said, "Distress the Midianim and attack them" (Bamidbar 25:17), the Moavim themselves all the more so [should be attacked]! Hashem [therefore] said to him: That which arises in your mind is not that which arises in Mine; there are two fine pigeons I must extract from them: Rus the Moaviah and Na'amah the Amonis.
My problem arises from the story told in Bamidbar 31, in which the command to attack Midian is actually carried out.
The pesukim describe how the Bnei Yisrael killed all of the Midiani men, while capturing the women and children. Moshe was upset at the army, as it was the women who caused the sin at Shittim; why were they left alive? Rather, they should kill all male children, all women who had had relations, and all female children who had not previously had relations would be left alive (v. 7-9, 14-18).
Presumably things would have been no different had Moav been included in the command as well; the fact that Moav was also to be attacked should not have impacted their decision to only kill the men and not the women, and Moshe's response would not have been different.
Therefore, Rus and Na'amah would still have been able to be born, if the Moavi children were left alive as well.
So how could Ulla claim this as a reason not to attack Moav?