He gave charity on the basis that by doing so all his sins would be forgiven
Im asking this question because this problem happens to many people.
With regard to the one who deliberately tells a lie about Allah and His Messenger, he is promised the punishment of Hellfire. It was narrated that Abu Hurayrah (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “Whoever tells a lie about me deliberately, let him take his place in Hell.”
Narrated by al-Bukhaari (110) and Muslim (2).
Some of those who tell lies about Islam think that they are doing something good if the lie is about virtues or encouraging people to do good deeds or deterring them from doing bad deeds.
Al-Nawawi (may Allah have mercy on him) said:
When he forbade lying about him, the Prophet (blessings and peace of Allah be upon him) did not differentiate between that which has to do with rulings and that which does not have to do with rulings, such as encouraging people to do good deeds, deterring them from doing bad deeds, exhorting and so on. All lies about him are haraam and are major sins and abhorrent actions, according to the consensus of those Muslims whose opinions are qualified to be taken as part of consensus, in contrast to the innovators of the Karaamiyyah group who falsely claimed that it is permissible to fabricate hadeeths with regard to encouraging people to do good deeds and deterring them from doing bad deeds, and they were followed in that regard by many ignorant people who claimed to be ascetics or who were classified as such by ignorant people. Their opinions, actions and evidence are indicative of a great deal of ignorance and negligence, and are the clearest proof that they have no knowledge of any of the basic rulings of Islam. In their views, they have combined many flaws that are suited to their foolish minds and corrupt way of thinking. They have gone against the words of Allah, may He be glorified and exalted (interpretation of the meaning): “And follow not (O man, i.e., say not, or do not, or witness not) that of which you have no knowledge. Verily, the hearing, and the sight, and the heart of each of those ones will be questioned (by Allaah)” [al-Isra’ 17:36]. And they have gone against the clear meaning of these mutawaatir hadeeths and well known hadeeths which regard false testimony as a very serious matter. And they have gone against the consensus of the scholars and other definitive evidence that proves that it is haraam to attribute words falsely to any individual, so how about the one whose words are part of sharee‘ah and regarded as Wahy (Revelation)? If you look at their words, you will find that they are telling lies about Allah, may He be exalted. Allah, may He be exalted, says (interpretation of the meaning): “Nor does he speak of (his own) desire. 4. It is only a Revelation revealed” [al-Najm 53:3].
End quote from Sharh Muslim, 1/70, 71
What is based on an invalid foundation is invalid. Whoever does any act of worship thinking that he will have a specific reward, then finds out that that is not so, will not have the reward that he thought he would get, because the issue of reward rests with Allah and does not depend on weak and fabricated hadeeths.
This does not mean that he is sinning, because of the hadeeth of Abu Hurayrah (may Allah be pleased with him) who said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “Whoever is given a verdict that is not based on proper knowledge, his sins will be on the one who gave him the verdict.” Narrated by Abu Dawood (3657) and Ibn Maajah (53); classed as hasan by Shaykh al-Albaani in Saheeh al-Jaami‘, 6069.
So this person who gave charity will have a reward for his charity, and charity is one of the causes of forgiveness for sins. But as to whether all sins will be forgiven because of charity, Allah knows best.
Shaykh al-Islam Ibn Taymiyah said, when discussing innovated acts of worship:
There is no doubt that the one who does them on the basis of his own misinterpretation or because he is following (a shaykh or scholar) will have one reward for his good intention and will be rewarded for his deed inasmuch as it is in accordance with sharee‘ah, and whatever there is of innovation in it may be forgiven on the basis that he tried to work out what was correct or he was following someone and thus may be excused. The same applies to whatever is mentioned of benefits of certain actions; whatever benefit is gained may be because of whatever in his action was in accordance with sharee‘ah, such as fasting, dhikr, reading Qur’aan, bowing, prostrating and good intentions in worshipping and obeying Allah and calling upon Him. And whatever it included of things that are disliked in sharee‘ah may be forgiven by Allah because he based his action of what he thought was best or he followed the example of someone else. And this is applicable to everything that may be mentioned of the benefits of some innovated actions that are disliked, but nevertheless this possible benefit does not cancel out the fact that it is disliked and forbidden, and one should do what is prescribed and has no innovation in it.
Iqtida’ al-Siraat al-Mustaqeem, p. 290
And Allah knows best.