But in Sotah, it appears to say grasshoppers! Thus:
How did grasshoppers, in the pasuk and in the gemara in Sotah, become ants?! People offer different answers. For example, there is the psychological drash, as from Rabbi Twersky, which is quite unlikely to be the truth behind this deviation in Rashi:
Second, there is a descending progression concerning feelings of low self-esteem. The spies initially felt like grasshoppers, but this feeling soon had them shrinking to the size of ants.Mizrachi has an alternate girsa which has chagavim instead, in which case Rashi indeed said grasshoppers. And see Minchas Yehuda (page 9) and Berliner. Some of the answers given are more plausible than others. Thus, the claim that it should be חנמלים with a chet rather than a heh, from chanamel to mean grasshopper, sounds initially promising, but is unlikely when we see the extremely good reason for nemalim to appear, namely that chagavim and nemalim are both translated by the same Aramaic word.
The gemara in Sotah, which is presumably Rashi's direct or eventual source, does not say חגבים. Rather, it says kematzim. And what are they? Look at Jastrow. It can mean hopper or locust. But it can also mean ant.
For example, in Berachot 54a:
'The stone which Og, king of Bashan wanted to throw at Israel'. This has been handed down by tradition. He said: How large is the camp of Israel? Three parasangs. I will go and uproot a mountain of the size of three parasangs and cast it upon them and kill them. He went and uprooted a mountain of the size of three parasangs and carried it on his head. But the Holy One, blessed be He, sent ants which bored a hole in it, so that it sank around his neck. He tried to pull it off, but his teeth projected on each side, and he could not pull it off.It is possible that Rashi simply made an error. Despite the fact that Targum Onkelos translates Chagavim as kamtzin, perhaps when looking at that gemara in Sotah, he saw kamtzin and thought ants. This is extremely unlikely, though. Not only would it make a lousy peshat in the gemara, Rashi himself on that daf in Sotah says that the meraglim heard them call them chagavim, locusts.
Another possibility, which I favor most strongly, is that Rashi believes that nemalim can mean grasshoppers. See how Jastrow notes that on Shabbos 77b, where we have:
Why is the proboscis of a locust soft [flexible]? Because it dwells among willows, and if it were hard [non-flexible] it [the proboscis] would be dislocated and it [the locust] would go blind. For Samuel said: If one wishes to blind a locust, let him extract its proboscis.where the word is קמץ, and it pretty clearly is referring to a locust. Yet Rashi there translates nemalah. Perhaps he even holds this is a particular kind of locust, and was being precise yet using a Hebrew word. Thus, Rashi is not saying "ants." He is saying locust. And nemalim, just like kamztin, can mean either locust or ant.
Another suggestion found in these commentaries was that Rashi decided that nemalim was the better translation here, because of the metzius that ants and not grasshoppers climb trees. I don't find this one likely.