Islam Commands us to Repay Evil with Good

A good action and a bad action are not the same. Repel the bad with something better and, if there is enmity between you and someone else, he will be like a bosom friend. (41:34)

Ward off evil with what is better. We know very well what they express. (23:96)

In these verses, God promises the faithful that they can secure positive results, so long as they adopt a pleasant attitude in the face of wrongdoing. The Qur'an emphasizes that even when a believer is dealing with an enemy, still he can establish a warm friendship. Responding to evil with good is also an essential part of compassion. When any believer sees others adopting an attitude that will not be pleasing to God, he considers first of all how that will affect them in the hereafter. Then he approaches them with toleration and humility, refusing to let himself become puffed up with pride.
Over the course of their lives, believers may come across people of very different characters. Yet they will not change their view of morality according to the people they meet. Others may speak mockingly, use ugly words, become angry, or even behave in a hostile manner. Yet the true believer never ceases to be polite, modest, and compassionate. He will not respond to ugly words with more of the same. He will not laugh at those who mock him, nor answer anger with anger, but remains patient and tolerant. In the face of insulting behavior, he will respond with proper morality, and with such compassion that the other will feel ashamed.
That is the morality our Prophet (may God bless him and grant him peace) recommends to us. In one of the hadiths, he says, "You do not return evil for evil, but excuse and forgive."-- 18 In another hadith, he calls on the faithful in these terms: "None of you must be the kind of weak person who says, 'He who has no compassion will receive none.' "19
In the Qur'an (5:13), our Prophet (may God bless him and grant him peace) was told to be forgiving when betrayed by some of the children of Israel:

… They have forgotten a good portion of what they were reminded of. You will never cease to come upon some act of treachery on their part, except for a few of them. Yet pardon them, and overlook. God loves good-doers.

As this verse shows, poor morality displayed by someone else is no justification for displaying the same thing. Each individual is solely responsible to God for his actions. According to the Qur'an, acting with compassion, affection and proper morality in the face of someone else's bad behavior is a sign of superior morality that reveals the extent of a believer's devotion to God. One verse (10:26) reveals the reward that such a pleasing attitude will bring:

Those who do good will have the best, and more! Neither dust nor debasement will darken their faces. They are the Companions of the Garden, remaining in it timelessly, forever.