Not only should our actions be “pure”, which is to say unsullied and well executed, but our thoughts and intentions should be, too. That’s to say that we should have the very noblest of motivations when we fulfill G-d’s mitzvot rather than do them for ulterior, self-serving reasons.
The truth be known, there’s a world of utilitarian reasons why we might do mitzvot. As Ramchal words it, we might want to “deceive others”, by having them think we’re deeply observant when we’re perhaps not; or we might calculate that we’d somehow be “honored or become wealthy” by our pious affect, in situations in which others might trust us with private information or property, or place us in honored positions on the assumption that we’re inherently honest. Or we may be anxious for a reward in the Afterlife.
At bottom the point is that it would be small of us to turn to things so lofty as mitzvot to raise our stature in others’ eyes. (Ramchal depicts the greatness of doing mitzvot altruistically in some of his more esoteric works; see especially his remarks in Tikkunim Chadashim 39, 69 as well as in Pinot HaMerkavah as found in Ginzei Ramchal p. 116.)
But what’s a mere mortal to do? We can’t deny the impressions that the good things that we do make on others any more than we can deny that we sometimes do indeed try to impress others by our observances. Are we to not fulfill G-d mitzvot if we can’t do them selflessly?
As our sages stated it, the answer is that “a person should always be involved in Torah and mitzvot despite any ulterior motives” and notwithstanding the risks, “so that he might come to do them altruistically” in the end (Pesachim 50b).
That is, we’re to do what’s to be done even if less than nobly since it’s what we’re asked to do as Jews. We’re nonetheless asked to strive toward selflessness later on and we’re promised that if we have that intention we’ll eventually come to be altruistic. As Ramchal reminds us though, the point remains that “if you haven’t yet reached the level of doing mitzvot altruistically after having done them for ulterior motives you’re still far from whole”.