Pesachim 50b:5פסחים נ׳ ב:ה׳
On the topic of reward for a mitzva fulfilled without intent, Rava raised a contradiction: It is written: “For Your mercy is great unto the heavens, and Your truth reaches the skies” (Psalms 57:11); and it is written elsewhere: “For Your mercy is great above the heavens, and Your truth reaches the skies” (Psalms 108:5). How so? How can these verses be reconciled? The Gemara explains: Here, where the verse says that God’s mercy is above the heavens, it is referring to a case where one performs a mitzva for its own sake; and here, where the verse says that God’s mercy reaches the heavens, it is referring to a case where one performs a mitzva not for its own sake. Even a mitzva performed with ulterior motives garners reward, as Rav Yehuda said that Rav said: A person should always engage in Torah study and performance of mitzvot, even if he does so not for their own sake, as through the performance of mitzvot not for their own sake, one gains understanding and comes to perform them for their own sake.
Psalms 108:5תהילים ק״ח:ה׳
For Thy steadfast love is great above the heavens: and Thy truth reaches the clouds.
Psalms 57:11תהילים נ״ז:י״א
For Thy love is great unto the heavens, and Thy truth to the clouds.