This verse (23:5) is difficult for two reasons. One, why does the Torah provide two reasons for the prohibition, the fact that they did not greet the Jewish people with food and that Bil’am was hired to curse the Jewish people? Only Moav hired Bil’am (Bemidbar 22:2-5), and hence a person from Ammon was prohibited from joining the Jewish people solely due to the reason that they did not greet the Jewish people with food and water, so why was this same reason not sufficient with respect to Moav? Two, Devarim 2:29 records that Moav sold the people food and water, so how could Devarim 23:4 state that they did not greet the Jewish people with food and water?
Ibn Ezra (on Devarim 2:29) records two answers to the second question. One, “in the name of the many,” is that while Moav sold the people food and water as indicated in 2:29, the problem in 23:5 was that they did not give the food freely to the people. Two, Ibn Ezra’s own approach, is that he argues that 2:29 does not state that Moav sold food to the people. 2:27,28 record that Moshe asked Sihon to allow the Jewish people to pass through his territory and Moshe offered that the Jewish people would buy food and water from Sihon. Afterwards, 2:29 records that Moshe asked Sihon to do to the Jewish people as Edom and Moav had done to the Jewish people. It is usually understood that the phrase “to do as Edom and Moav had done” in 2:29 refers back to Moshe’s offer to buy food and water in 2:28, that Moshe was asking Sihon to sell food and water to the Jewish people like Edom and Moav had sold food to the people. However, Ibn Ezra argues that the phrase “to do as Edom and Moav had done” refers back to 2:27 that Moshe was asking Sihon to let the Jewish people pass through his land as Edom and Moav had let the Jewish people pass through their lands.
The Ramban (on 23:5) rejects both answers quoted by the Ibn Ezra. He rejects the idea that the problem with Moav was that it sold food instead of giving the food away for free since selling the food is also reasonable and could not be sufficient cause to prohibit a person from Moav of joining the Jewish people. Ramban’s question seem cogent to me but Hoffmann (on 2:29) also likes this distinction between selling and giving away, as he argues that Moav should have been like Malki-Tzedek who brought food to Avram (Bereshit 14:19). Yet, this example is not applicable here, as Malki-Tzedek brought food as tribute and thanks for Avram, while Moav did not owe the Jewish people any thanks. Furthermore, Malki-Tzedek bought food for one person, would one expect that Moav should feed the entire Jewish nation for free? Finally, again even if they should have fed all the people for free, still as the Ramban asked was selling food so horrible a crime that they could never join the Jewish people?
The Ramban also rejects Ibn Ezra’s approach that 2:29 does not imply that Moav sold food to the people. According to Ibn Ezra’s reading of 2:29 Moshe asked Sihon to let the people pass through Sihon’s lands just as Edom and Moav had let the people pass through their lands. However, as pointed out by Ramban, the Jewish people did not pass through Edom or Moav’s land. Thus, the phrase in 2:29 “to do as Edom and Moav had done” must mean that Moshe asked Sihon to sell the people food as Edom and Moav sold the people food.
The Ramban suggests a different answer based on the fact that two reasons are recorded in 23:5 for the prohibition of Ammon and Moav to join the Jewish people. His suggestion is that one reason refers to Ammon and one to Moav. A person from Ammon could not join the Jewish people since they did not sell the people food, while a person from Moav could not join the Jewish community since they hired Bil’am. This approach answers both of the questions raised above: the Torah had to record two reasons, and 23:5 does not contradict 2:29 because with this reading 23:5 only implies that Ammon did not sell food and water to the Jewish people not Moav.
The Abravanel rejects Ramban’s answer for a grammatical reason. 23:5 switches from the plural to the singular, that “they did not greet the people” as opposed to “he hired Bil’am.” Abravanel argues that the plural in 23:5 means that both Moav and Ammon did not greet the people, while the singular in 23:5 means that only Moav hired Bil'am. Abravanel notes that also in Nehemiah 13:2,3, the plural is used to indicate that both Moav and Ammon did not greet the people. Instead, Abravanel offers a different reading of 2:29 which is not clear to me.
My guess is that the questions can be answered if we understand the geography of where the people marched in the 40th year in reference to Moav. While 2:29 records that Moav sold food to the Jewish people, the verse does not refer to all of Moav but rather to those people of Moav who lived in Ar. What and where is Ar? Tigay (JPS, 1996, p.526, footnote 6,7) writes that Ar was a city of Moav, and from 2:18 it seems that it was “situated near the border on the Wadi Arnon.” Wadi Arnon was the border between Moav and the Amorites, with Moav south of the Wadi, and the Amorites, whose king was Sihon, north of the Wadi. This means that Ar was situated in northern Moav just south of the Wadi Arnon. When the Jewish people marched in the 40th year, they skirted around Moav, and then they had to pass through the Amorite land to get to the land of Israel. The people crossed Wadi Arnon and then Moshe sent messengers to Sihon, Bemidbar 21:13-23. Moshe was already in the land of Sihon (the periphery) when he sent the messengers to Sihon, and the people were north of Moav. However, they were still close to Ar, the Moav city by the Wadi Arnon, and this offered the people of the city the opportunity to sell food and water to the Jewish people as indicated in 2:29.
This selling does not contradict 23:5 that the people of Moav did not greet the Jewish people with food and water since the people of Ar only sold the Jewish people food after the Jewish people had passed them by. When the people were marching around Moav, the people of Moav did not sell them any food or water. Accordingly, Moav did not greet the Jewish people with water and food, as greeting means to go out to a person, while Moav waited until the Jewish people passed them by to sell them food. Therefore, both Moav and Ammon did not greet the Jewish people to sell them food or water. Yet, still one could ask that if in the end some people of Moav sold food to the Jewish people, then this should have been sufficient to allow them the opportunity to enter the Jewish people? The answer is that Moav had a double sin that they also hired Bil’am to curse the Jewish people. Thus, the Torah had to mention two reasons why Ammon and Moav could not enter the Jewish community.
Fox, Everett, 1995, The Five Books of Moses: A new translation, New York: Schocken Books.