Doing good for an ulterior motive isn’t always such a bad thing…
Moshe Rabbeinu reminds the Jewish people about the time they believed the scouts’ report about Eretz Yisroel. He tells them that their children, who didn’t take part in that episode would merit to enter the Land.
“[Furthermore,] your young children, [about whom] you said, ‘They will be prey,’ and your children who on that day did not know good and evil, they will go there and I will give it to them, and they will posses it.” Devorim 1:39, (beginning of revi’i)
Moshe Rabbeinu promises the Jewish people that even the “young children” will merit to enter the land. What is the need to emphasize the “young children?” The scouts said everyone would be prey, even the adults!
A “young child” in avodas Hashem is one whose avoda is not completely selfless. Even the slightest ulterior motive makes our avoda childlike. Torah is compared to food and specifically bread. When children eat, they crumble their food and scatter it—in fact, sometimes children will scatter more than they’ll eat! (Lekket Tov, VaYigash 47, 12) The same applies to our avoda: the food (Torah which is compared to bread) fails to enter the child (the person) internally.
This was the claim of the scouts: “If we enter the Land and become involved with earthly, material matters, our avoda and our observance of Torah will lose its selflessness, its purity!” They thought that their “food” would become “scattered.”
This is why Moshe Rabbeinu mentions the “young children.” The kind of relationship G-d has with a child is more dear to Him than that of the Generation of the Desert. It is endearing when a person practices iskafya (self-control). The child wants other things—which are perhaps unholy—even when we serve Hashem, we may come come from a place of self-interest. When we practice self-control and do another mitzvah, learn more Torah, etc., we become more dear to Hashem.
Likkutei Sichos vol. 2, page 581