Undoubtedly, Islam motivates us to do good, and Allah rewards us for doing it. Islam aims to guarantee security to the members of society regarding their lives and property. Thus, Islam forbids robbing or stealing others’ property, as well as it rejects doing good deeds using ill-gotten money.
Delving into this issue, the late prominent Muslim scholar Sheikh Ahmad Ash-Sharabasi, professor of `Aqeedah and Philosophy at Al-Azhar University, stated:
No doubt, building mosques and schools and doing such like things are considered among the recommended acts of obedience which draw one closer to Allah; but the person expected to do such good deeds should do them from good and lawful money, not from ill-gotten gains. In this regard, the Prophet (peace and blessings be upon him) said, urging Muslims to earn only lawful money, “Allah is All-Pure and He, therefore, accepts only that which is pure.” He (peace and blessings be upon him) also warned Muslims against unlawfully gained money: “Whatever a body grows thanks to ill-gotten money, it is more entitled to be admitted to the Hellfire.”
One should ask oneself, “How could Allah reward someone who has stolen, robbed, or gambled, then builds a mosque, a school, or a hospital from such money he acquired through these illicit ways or any other illegal ways?”
Muslim jurists have stated that when anybody intends to perform Hajj, he should do so with lawful money. They further have said that if someone performs Hajj with ill-gotten money, Allah does not accept his Hajj nor does He reward him for such Hajj. But jurists regard his performance of the Hajj as valid, and in this case he is deemed as doing the obligatory Hajj; however, he is considered doing a sin by using unlawful money in this act of obedience. This is the same as the case of someone who prays in a place which he unlawfully acquired: The performance of prayer itself is valid and he is regarded as doing the obligation due on him, but he is still considered guilty for acquiring this place illegally. This is applicable in the case of building a hospital or a school with ill-gotten money; people may make use of such buildings but the one who has built them is not rewarded like the one who spends for charity from his lawful money.
On the other hand, if someone has ill-gotten property and does not know its owner and cannot return it to its origin, then he should turn to Allah in sincere repentance and spend this money in charitable ways.