It is possible to perform the mitzvah of waving the lulav (palm branch) with an etrog (citron) only if it is not fruit that comes from a tree in the first three years after it is planted, from which one may not gain benefit.
Similarly the performance of any precept involving a transgression.
Since it was performed with something forbidden, it cannot rise to holiness.
So, too, money given to charity which had been dishonestly acquired; and similarly with other things.
Just as food can be either kosher or unkosher, so too can money be either kosher or unkosher.
Although kosher money is not yet holy, one may benefit from it, and thus one may also perform a mitzvah with it.
On the other hand, one may not gain benefit from stolen, unkosher money; one cannot perform a mitzvah with stolen funds and raise them to holiness.
In this sense, the halakhic determination as to whether something is forbidden or permissible is a statement about its character, about whether or not it can be rectified and elevated to holiness.
–Rabbi Adin Steinsaltz
From Understanding the Tanya, p. 244 by Rabbi Adin Steinsaltz