Praying in mosques built from forbidden money
Sheikh Atiyyah Saqr- may Allah have mercy on him- says:
This act is far away from the reward of building a mosque, because the reward is given to the obedient believer who has a lawful income. The scholars have said: If a Disbeliever donates to build a mosque, or to help prepare it, then it is accepted from him in this life, and the prayer is valid in it, even if there is no reward for it with Allah in the after life, and his reward in this life for example how people honor him, Allah SWA says: Then We shall advance upon the work which they have done and render it as scattered dust.
Imam Shafi; explained that it is allowed for a non muslim to make a will to build a mosque for the muslims, even if it is Masjid Al Aqsa.
Also it is allowed in the book of the Hanafis that the building of a mosque for the muslims by a non muslim, or making his house a mosque for them. It is allowed to pray in these mosques, and the prayer is valid.
And if this ruling is on the validity of the prayer in a mosque built by non muslim, then the prayer is valid. If it was built or donated by a Muslim, even if he was a sinner, committing all kinds of sins; because he is still a believer despite his disobedience, as long as he does not associate anything with Allah, then we leave his reward to Allah SWA.
The Scholars have stated that repentance from money made by forbidden means is done by returning it to its owner, if they know, and if they do not know then that money is used for a general benefit for the muslims, and from that is mosques, and this confirms the statement regarding the validity of the prayer in mosques built using money that is earned from non halal means.