Indulgences for contributing to any good work, are different from the charges made by the Protestants against the Church.
For an indulgence to be applicable, there are certain things that must be met. These are quite different from what Luther and modern day Protestants charge.
Protestants charge that an indulgence is a “get out of jail free” card, that one purchased an indulgence and did not have to have any sorrow for one’s sins. They claimed that Catholics believed that if you purchased an indulgence you where free to sin, as the indulgence “balanced out” the guilt for your sins.
The real story is quite different. One can fulfill all the requirements to gain an indulgence, which could include, feeding the poor, saying the rosary or other prayers daily, etc. but if you are in a state of unrepentant sin, you do not gain an indulgence. If however you are sorry for your sins, go to confession and receive absolution, preform the actions required (as above, good works, prayers or whichever indulgence you are intending to obtain) and usually receive communion and say prayers for the intentions of the Pope, you can receive an indulgence. Unlike what the Protestants claim, the indulgence has no effect on sins not yet committed, but rather effect the temporal punishment of sins we committed in the past, or the punishment due to those in Purgatory. We can transfer the effects of an indulgence to someone who is in Purgatory, and that itself is a meritorious action, but we cannot transfer the effects of an indulgence to someone else who is living. (The reason given is that the living can do meritorious acts and those in Purgatory cannot, but depend on two things, either the purgation of their sins (cleansing done by God in purgatory) or our own meritorious actions which we apply to them. Once again we cannot gain these merits if we are in a state of mortal sin, and remain unrepentant.
So the charge that the Church could or did sell indulgences so people could buy their way out of Hell is a false accusation that some historians and people who have no interest in investigating what the real teachings about indulgences have perverted in an attack against the Church, or have been taught as Catholic doctrine when in fact it contradicts both what the Catholic Church teaches, and what the Church can do.
Any number of historians can claim that Leonardo Da Vinci was Chinese, and his skin was striped yellow, green and red. Such claims don’t make it historical fact. Any number of historians can claim that the Church sold indulgences, to buy ones self or ones relatives out of hell, and as Protestants (following the lead of Luther) claim that one did not have to be sorry for ones sins, or now had a license to sin in the future, but that does not make their claim valid.