Praise be to Allah.
Prohibition of riba in Islam
Allah says (interpretation of the meaning): “O you who believe! Be afraid of Allah and give up what remains (due to you) from Riba (from now onward) if you are (really) believers.” [al-Baqarah 2:278]
This is a call from Allah to give up riba and avoid it, because He has forbidden riba:
“Allah has permitted trading and forbidden Riba”. [al-Baqarah 2:275 – interpretation of the meaning]
Consumption of riba is one of the causes of the humiliation of the Muslims, as the Prophet (peace and blessings of Allah be upon him) said: If you engage in ‘inah transactions, and are content with farming and hold on to the tails of cattle, and you forsake jihad for the sake of Allah, Allah will cause you to be humiliated and will not relieve you of that until you return to your Religion.” (Narrated by Abu Dawud, 3462; classed as sahih by al-Albani in al-Silsilah al-Sahihah, 11)
[Translator’s note: ‘inah transaction means to sell something for a price to be paid at a later date, then to buy it back for a lower price (to be paid immediately); this is a trick used to circumvent the prohibition on lending with interest]
Does sinning break your fast?
With regard to the fast of one who commits a major sin – such as buying shares in a riba-based bank – it is valid but is imperfect, and he may not attain the reward of fasting.
Think about the words of Allah (interpretation of the meaning):
“O you who believe! Observing As-Sawm (the fasting) is prescribed for you as it was prescribed for those before you, that you may become Al-Muttaqun (the pious).” [al-Baqarah 2:183]
In this verse Allah mentions the reason why fasting is enjoined, which is as a means of fearing Allah by doing obligatory duties and avoiding haram things.
The Prophet (peace and blessings of Allah be upon him) said: “Whoever does not give up false speech and acting upon it, Allah has no need of his giving up his food and drink.” (Narrated by al-Bukhari, 1903) In other words, Allah does not simply mean that we should give up our food and drink when fasting, rather He wants us to fear Him, because He says (interpretation of the meaning):
“… that you may become Al-Muttaqun (the pious)” [al-Baqarah 2:183] (See al-Sharh al-Mumti’, 6/435)
Al-Hafiz ibn Hajar (may Allah have mercy on him) said:
“False speech and acting upon it” – what is meant by false speech is lying , and acting upon it means doing what is implied by that.
Ibn al-‘Arabi said: what is meant by this hadith is that whoever does what is mentioned will not be rewarded for his fasting; the reward for fasting cannot outweigh the sin of false speech etc.
Al-Baydawi said: the purpose behind the prescription of fasting is not just to be hungry and thirsty, rather the purpose is what that leads to of suppressing desires and taming one’s evil inclinations. If this is not achieved, then Allah will not regard it as acceptable.
It was understood (by some) from this that these actions invalidate the fast.” (Fath al-Bari)
And Allah knows best.