When should one forgive and when punish?
What matters is the effect of forgiveness. If it reforms the wrongdoer, one should forgive. If instead it encourages further wrongdoing, one must not forgive.
There is no rigid list of rules for this question. Even so, it is not hard to answer. Deep down, every person knows when to forgive and when not to, if they listen honestly and with a pure heart to their inner self.
An everyday example makes this clear. A child has done something wrong. If you forgive the child and all it learns is that wrongdoing has no consequences, then forgiveness promotes wrongdoing. In that case it is a moral duty not simply to forgive. But if forgiveness makes the child ashamed and it changes for the better, then you choose forgiveness without hesitation.
This is exactly what the first verse above teaches. A punishment must never exceed the wrong done. But whoever forgives and thereby brings about reformation has their reward with Allah. The aim, then, is not revenge but that the person becomes better.
This teaching fits human nature. Islam holds that God’s commandments and the nature He gave to human beings belong together. That is why what a pure conscience advises agrees with what the Holy Qur’an teaches.
The hadith above shows the same thing in the life of the Holy Prophet Muhammad (saw). He did not seek revenge for wrongs done to himself. But where God’s commands were violated and the welfare of others was at stake, he upheld justice.