Parshas Ki Seitzei bars an Ammonite or Moavite from marrying into the Jewish people even unto the tenth generation. While an Edomite and Egyptian may marry in the third generation.
What's the fundamental basis for the distinction?
The ban on Ammon and Moav follows that of the one on bastards and indeed both nations are the products of incest. Improper relations of this sort are occasionally referred to in the Torah as "Chessed" or kindness because they have the appearance of love to them.
The distinction goes to the two types of anti-Semitism defined by the Edomites and the Moavites.
Edom and Egypt were open in their hostility toward the Jews. They sought to persecute and kill them. Whatever malice they had depends on their strength and their national power. By the third generation they no longer present a danger. However Ammon and Moav represents a more insidious form of corruption as they demonstrated by hiring Bilaam and then attempting to corrupt the Jews.
Rather than bringing bread and water, true Chessed, to the Jews, they instead practiced a false Chessed, as that of their incestuous origins, by attempting to corrupt and pervert the Jews. Their weapon was intimate and insidious. Like the Caananites they could not be allowed to marry in even into the tenth generation because their form of hatred and evil represents a permanent threat.
Open enemies are easy to identify and defend against. Covert enemies however are far more insidious because they come disguised as friends. They appear to be on a mission of Chessed, but like the adulterous love that produces the Mamzer, their love is purely selfish, cruel and leads to destruction.
Some anti-Semites, like Edom and Egypt are open about their agenda. They believe that Jews are inferior and to be stamped out. They hatred is lethal, but not insidious. It is out in the open. The hatred of Ammon and Moav is more insidious because it is based on a jealous malice that recognizes the spiritual gifts of the Jews and seeks to corrupt and destroy them.
When they hate, Edom and Egypt come as enemies. But their occasional acts of kindness, as when Esav kissed Yaakov or when Egypt provided sanctuary to the Jews, are sincere. They have no hidden agendas. But when Ammon and Moav hate, they come as friends. Like Bilaam, they flatter in order to curse, they disguise their poison in compliments, their Chessed is false and fatal.
Jealousy is one of the most poisonous human traits. Its enmity is more dangerous because its possessors often do their worst while posing as friends.
Enemies like Edom, who were once family, may be redeemed. But the incestuous and adulterous relationship poisons love and whatever kinship once existed. It is based on a toxic brew of jealousy and selfishness that destroys everything it touches. Egyptians and Edomites could find a place within the Jewish people despite their atrocities, but Ammon and Moav could not because they would remain compelled to corrupt and undermine by their own jealous and selfish motives.
Egypt and Edom could come to respect the Jews, as Esav came to respect Yaakov and Pharaoh came to respect Moshe, but jealousy is not deterred by respect. Ammon and Moav did not need to learn what Esav and Pharaoh learned painfully. They already knew it. It only fed their jealous hatred.
Therefore you may not seek their good, for their selfishness and jealously will only turn it into evil.
Historically the worst enemies of the Jewish people came from corrupted members from within their own ranks. That is still true today. Enemies with Jewish last names motivated by narcissism and malice, jealousy and neurotic paranoia, who seek to kill and destroy Jews are our most ruthless and dedicated enemies.