From the Quranic perspective, doing good inherently has no negative outcome. What we perceive as such is often a divine test, part of hidden divine wisdom, or a result of insincerity or human reactions. The reward for goodness is always preserved with Allah.
From the perspective of the Holy Quran, the concept of 'doing good' (Ihsan) or 'righteous deeds' (Amal Saleh) is always associated with reward and goodness, and it never goes unrequited. Allah Almighty explicitly promises in numerous verses that He will not waste the reward of those who do good. However, your question, 'Why do good deeds sometimes have negative outcomes?', stems from our understanding of the concept of 'outcome,' its timing, and the external and internal factors involved, to which the Quran refers. This phenomenon, sometimes superficially labeled a 'negative outcome,' is, from a Quranic standpoint, often part of a deeper divine wisdom, a test for the believer, or a result of human factors beyond the control of the doer of good, rather than the good deed itself being inherently bad or leading to bad. One of the most important principles emphasized by the Quran is the concept of 'Divine Trial' or 'Ibtila'.' Life in this world is a grand arena of test where Allah tests humans with various challenges and situations. In Surah Al-Ankabut, verses 2 and 3 state: "أَحَسِبَ النَّاسُ أَن يُتْرَكُوا أَن يَقُولُوا آمَنَّا وَهُمْ لَا يُفْتَنُونَ * وَلَقَدْ فَتَنَّا الَّذِينَ مِن قَبْلِهِمْ ۖ فَلَيَعْلَمَنَّ اللَّهُ الَّذِينَ صَدَقُوا وَلَيَعْلَمَنَّ الْكَاذِبِينَ" (Do people think that they will be left to say, 'We believe' and they will not be tried? But We have certainly tried those before them, and Allah will surely make evident those who are truthful, and He will surely make evident the liars). Sometimes, doing good and showing kindness to others is part of this test. You might encounter ingratitude, misunderstanding, or even hostility in return for your good deed. This apparent 'negative outcome' is not due to the badness of your action, but rather to gauge your patience, perseverance, sincerity, and reliance on Allah. Do you do good for worldly reward, or for the pleasure of your Lord? These tests refine faith and help individuals achieve perfection and higher spiritual ranks. Another reason is 'hidden divine wisdom.' Humans possess limited knowledge and cannot comprehend all dimensions of an event. The Quran in Surah Al-Baqarah, verse 216 states: "وَعَسَىٰ أَن تَكْرَهُوا شَيْئًا وَهُوَ خَيْرٌ لَّكُمْ ۖ وَعَسَىٰ أَن تُحِبُّوا شَيْئًا وَهُوَ شَرٌّ لَّكُمْ ۗ وَاللَّهُ يَعْلَمُ وَأَنتُمْ لَا تَعْلَمُونَ" (But perhaps you hate a thing and it is good for you; and perhaps you love a thing and it is bad for you. And Allah Knows, while you know not). According to this noble verse, what appears undesirable or 'negative' to us might, in essence and in the long run, be entirely for our good and benefit. Perhaps the good deed that seemingly yielded a bad result saved you from a greater evil, taught you an important lesson, or opened a new path for your spiritual growth. These seemingly unpleasant occurrences can remove arrogance and pride from a person, make them more humble, or decrease their attachment to worldly life. Allah, with His infinite knowledge, knows the ultimate outcomes and the true good and bad, while we only see a small piece of the puzzle. The importance of 'sincerity of intention' (Ikhlas) is also vital in this context. The Quran emphasizes performing righteous deeds solely for the sake of Allah's pleasure, not for fame, people's praise, or worldly gains. In Surah Al-Bayyinah, verse 5, it states: "وَمَا أُمِرُوا إِلَّا لِيَعْبُدُوا اللَّهَ مُخْلِصِينَ لَهُ الدِّينَ حُنَفَاءَ وَيُقِيمُوا الصَّلَاةَ وَيُؤْتُوا الزَّكَاةَ ۚ وَذَٰلِكَ دِينُ الْقَيِّمَةِ" (And they were not commanded except to worship Allah, [being] sincerely obedient to Him, inclining to truth, and to establish prayer and to give zakah. And that is the correct religion). If the intention is not pure and there is an expectation of reward or praise from creatures, one might feel a 'negative outcome' if those expectations are not met. This feeling actually results from a mismatch between worldly expectations and reality, not from the good deed itself. An action done with sincerity, even if it faces difficulty in this world, is preserved with Allah and carries immense eternal reward. Another factor that can lead to such a perception is the 'behavior and reactions of other human beings.' Some individuals, due to envy, malice, ignorance, or weakness of character, react negatively even to kindness. The history of prophets and divine saints is full of examples where, despite inviting to good and performing miracles, they faced denial, accusations, and persecution from their people. These reactions are signs of corruption in the heart of the reactor, not a defect in the good deed performed. In such situations, the Quran advises believers to be patient and steadfast. In Surah Hud, verse 115, it states: "وَاصْبِرْ فَإِنَّ اللَّهَ لَا يُضِيعُ أَجْرَ الْمُحْسِنِينَ" (And be patient, for indeed, Allah does not allow to be lost the reward of those who do good). This verse assures that even if you face adversities in this world, the reward for your good deed is preserved with Allah and will not be lost. This reward may manifest in this world as hidden blessings, spiritual peace, or divine guidance, and will certainly be eternal and infinite in the Hereafter. Therefore, from the Quranic perspective, 'doing good' never has a truly negative outcome; rather, it always brings goodness and blessings. What we sometimes mistakenly call a 'negative outcome' is actually a manifestation of divine wisdom, a test to strengthen faith, or a reflection of human flaws in the recipients of kindness. The believer's duty is to continue on the path of Ihsan with pure intention and complete reliance on Allah, regardless of apparent results and worldly expectations, for Allah's promise to preserve the reward of those who do good is a true and unfailing promise.
But perhaps you hate a thing and it is good for you; and perhaps you love a thing and it is bad for you. And Allah Knows, while you know not.
Do people think that they will be left to say, 'We believe' and they will not be tried?
But We have certainly tried those before them, and Allah will surely make evident those who are truthful, and He will surely make evident the liars.
And be patient, for indeed, Allah does not allow to be lost the reward of those who do good.
And they were not commanded except to worship Allah, [being] sincerely obedient to Him, inclining to truth, and to establish prayer and to give zakah. And that is the correct religion.
It is narrated that a hunter caught a fox in his trap. The fox pleaded earnestly, saying, 'O generous man, if you release me, I will guide you to a hidden treasure.' The hunter's heart softened, and thinking the fox was sincere, he freed it. The fox went ahead, and the hunter followed. The fox led him into a desolate wilderness full of thorns and bushes, then fled. The hunter returned, wounded and exhausted, and said to himself, 'Why did I trust an animal whose nature is deceit and trickery? My good deed brought nothing but wounds and exhaustion.' This story reminds us that sometimes, kindness shown to the ignorant or deceitful yields nothing but harm. One must act with wisdom and discernment in doing good, and not expect results from creation, but rather entrust them to the Creator.