Our Gemara on Amud Aleph discusses the status of the Biblically penalty of an extra fifth imposed for one who confesses that he denied a theft under oath. The particular case is regarding someone who stole from his father, and then denied it under oath, and before he can make restitution, his father dies. Technically, he inherited part of the fine due to his father, and one might think that his percentage of the inheritance should be deducted off the fine, while paying the balance. However, the actual rule is that he must pay his brothers the full fine so he fulfills the requirements for penance. Rav Yosef discusses what he should do if he is unable to find any relatives. In such a case, he should give the fine to tzedakah.
Tzedakah seems to be an all purpose solution, when the regular channel for a mitzvah is unavailable, so as to make up for the payment due his kin.
Sefer Chassidim (764 and 765) offers guidance to an individual who sought counsel regarding being denied a mitzvah. In his town, the kibbud of rolling the Torah (which probably includes what we call Hagbah) was auctioned off in exchange for a donation to the local indigents. This individual had a consistent practice of purchasing this privilege, and he was attached and devoted to this mitzvah. One time, a group of unsavory individuals ganged up on him and outbid him by a large margin, monopolizing ownership of this mitzvah throughout the year. The petitioner was in a moral conundrum: On the one hand, he felt this contingent was not worthy of the mitzvah due to their poor character, “and some of them cannot even read a verse.” But on the other hand, if he intervenes, in the end, the impoverished folks will lose out on the extra money. Apparently, due to his stature and recognition in the community, the person had the ability to protest and retain his chazakah on the mitzvah, despite not being able to outbid his competitors.
The answer given was, even though the bidders were not worthy and insincere, he should let them win, so as to increase the amount of funds made available for charity. Then, he adds an important line: If he will continue to give what he used to give to tzedakah, even though he is now losing the bid, it will be considered a zechus for him as if he gave the larger amount of his opponent bidders.
This is a fascinating idea, which may have practical applications. Consider a situation where one is outbid for an Aliyah. There is no obligation, but I wonder if, based on this, he chose to pay his last offered amount. Would he get the same zechus of tzedakah as if he was the highest bidder?
Sefer Daf al Daf brings down the MIshnas Avraham commentary on Sefer Chassidim who goes even further. He says we see from Sefer Chassidim that in regard to any mitzvah that involved a payment but is unable to fulfill, if one gives that payment to tzedakah, he receives the merit as if he performed that mitzvah. For example, if you would normally buy an Esrog for $100 and one year there are no Esrogim available, if you gave that $100 to charity, it would count as if you did the mitzvah of Esrog!
I wonder if we may extrapolate beyond money, and broaden it to any effort. Say a person is unwell and cannot fast on Yom Kippur, but his doctors say that he would be fine just drinking water. Would abstaining from solid food, which is the farthest effort he can make, count as if he fully fasted? Or, perhaps there is something special and redemptive of tzedakah, and thus this principle only applies when you donate the amount of money you would have expended on the mitzvah. Then in the case of fasting, while it might be meritorious to abstain as much as possible, it still does not count as the mitzvah. While there is also a halakha that certain fasts can be redeemed by giving the value of the food that he eats to tzedakah (Shulchan Aruch 334:26), that may not be related to this zechus. As the case in Sefer Chassidim involves giving a payment equal to what he would have paid for the mitzvah, in our situation, fasting costs no money. So while a sign of sincerity and devotion, it is unclear if these actions would ensure the same merit of the mitzvah itself.