King David was a descendant of Rut HaMo’avia – Ruth the Moabite (see Ruth 4:17).
Our Gemara relates that when King Saul was concerned that David would claim the monarchy, his advisor, Doeg HaEdomi argued – convincingly – that David should be forbidden from being considered a true member of the Jewish people, due to this ancestry. According to Rava, a man named Amasa (see II Shmuel 17:25) rose in David’s defense and threatened to stab anyone who rejected the teaching that women from Ammon and Mo’av were allowed to marry into the Jewish community, even though the Torah prohibits males from doing so. He argues that, Doeg’s proofs notwithstanding, he had a tradition from the prophet Shmu’el and his court that such women were permitted.
The disagreement revolved around the question of how to understand the reason given by the Torah for the limitation on people from Ammon and Mo’av. The Torah explains (see 23:5) that this is punishment for the fact that they did not offer bread and water to the children of Israel during their trek through the desert. The traditional perspective is that it was the responsibility of the men to welcome the tired strangers, so the prohibition was limited to them. Doeg argued that the men should have welcomed the men and the women should have welcomed the women – an assertion that was rejected by Shmu’el and his court.
The Rashba raises a different question on this source. The people who did not greet the children of Israel with bread and water were the people of Ammon, yet Ruth was from the nation of Mo’av. How do we know that the same exclusion applies to that nation? Several answers are suggested, but the simplest approach may be that of the Talmud Yerushalmi, which points out that the sin of Mo’av was that Balak, their king, hired the services of the prophet Bilam to curse the people. The Yerushalmi argues that the women of Mo’av played no role in that incident at all.