Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) said concerning this saying of Allah Almighty, "So whoever transgresses against you, transgress against him in the same way that he transgressed against you" [Surah al-Baqarah: 194], and this saying, "And whoever takes revenge after having been wronged, against them there is no way (of blame)" [Surah al-Shura: 41], and this saying of Allah Almighty, "And if you punish, then punish with the like of that with which you were harmed" [Surah al-Nahl: 126], and this saying, "The recompense of an evil is an evil like it" [Surah al-Shura: 40]: These verses and others like them were revealed in Makkah, and the Muslims in Makkah were few; they had no leader to rescue them from the harm of the polytheists, so the Muslims were commanded: whatever harm the polytheists inflict on you, repay it yourselves in kind, or bear it patiently and forgive, and that is better. When the Messenger of Allah (peace and blessings be upon him) migrated to Madinah and Allah Almighty honoured him with authority, the Muslims were commanded to bring their mutual disputes before their ruler and not to become enemies of one another like the people of ignorance. He said: "And whoever is killed wrongfully, We have given his heir authority, so let him not exceed limits in killing; indeed he is supported" [Surah al-Isra: 33]: the ruler should help him and secure justice for him from the wrongdoer; and whoever settles his own case without the ruler is disobedient, transgressing, and doing the deed of the Jahiliyyah, one who was not pleased with the judgement of Allah.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنايات / 16080