The commandment against revenge is explained as training a person to uproot hatred and remember that human beings should act with compassion and mutual benefit.
שֶׁלֹּא לִנְקֹם – שֶׁלֹּא לִנְקֹם. כְּלוֹמַר, שֶׁנִּמְנַעְנוּ מִלָּקַחַת נְקָמָה מִיִּשְׂרָאֵל, הָעִנְיָן הוּא, כְּגוֹן יִשְׂרָאֵל שֶׁהֵרַע אוֹ צִעֵר לַחֲבֵרוֹ בְּאֶחָד מִכָּל הַדְּבָרִים, וְנֹהַג רֹב בְּנֵי אָדָם שֶׁבָּעוֹלָם הוּא שֶׁלֹּא יָסוּרוּ מִלְּחַפֵּשׂ אַחֲרֵי מִי שֶׁהֵרַע לָהֶן, עַד שֶׁיִּגְמְלוּהוּ כְּמַעֲשֵׂהוּ הָרַע אוֹ יַכְאִיבוּהוּ כְּמוֹ שֶׁהִכְאִיבָם, וּמִזֶּה הָעִנְיָן מְנָעָנוּ הַשֵּׁם יִתְבָּרַךְ בְּאָמְרוֹ (ויקרא יט יח) לֹא תִקֹּם. וּלְשׁוֹן סִפְרָא (קדושים ד י) עַד הֵיכָן כֹּחָהּ שֶׁל נְקָמָה? אָמַר לוֹ הַשְׁאִילֵנִי מַגָּלְךָ וְלֹא הִשְׁאִילוֹ, לְמָחָר אָמַר לוֹ הַשְׁאִילֵנִי קַרְדֻּמְּךָ, אָמַר לוֹ אֵינִי מַשְׁאִילְךָ כְּדֶרֶךְ שֶׁלֹּא הִשְׁאַלְתָּ לִי מַגָּלְךָ, לְכָךְ נֶאֱמַר, לֹא תִקֹּם. וְעַל כְּגוֹן זֶה הַקֵּשׁ כָּל הַדְּבָרִים. מִשָּׁרְשֵׁי הַמִּצְוָה. שֶׁיֵּדַע הָאָדָם וְיִתֵּן אֶל לִבּוֹ כִּי כָּל אֲשֶׁר יִקְרֵהוּ מִטּוֹב עַד רַע, הוּא סִבָּה שֶׁתָּבוֹא עָלָיו מֵאֵת הַשֵּׁם בָּרוּךְ הוּא. וּמִיַּד הָאָדָם מִיַּד אִישׁ אָחִיו לֹא יִהְיֶה דָּבָר בִּלְתִּי רְצוֹן הַשֵּׁם בָּרוּךְ הוּא, עַל כֵּן כְּשֶׁיְּצַעֲרֵהוּ אוֹ יַכְאִיבֵהוּ אָדָם יֵדַע בְּנַפְשׁוֹ כִּי עֲוֹנֹתָיו גָּרְמוּ, וְהַשֵּׁם יִתְבָּרַךְ גָּזַר עָלָיו בְּכָךְ, וְלֹא יָשִׁית מַחְשְׁבוֹתָיו לִנְקֹם מִמֶּנּוּ, כִּי הוּא אֵינוֹ סִבַּת רָעָתוֹ, כִּי הֶעָוֹן הוּא הַמְּסַבֵּב, וּכְמוֹ שֶׁאָמַר דָּוִד עָלָיו הַשָּׁלוֹם (שמואל ב טז יא) הַנִּחוּ לוֹ וִיקַלֵּל כִּי אָמַר לוֹ יְיָ. תָּלָה הָעִנְיָן בְּחֶטְאוֹ וְלֹא בְּשִׁמְעִי בֶּן גֵּרָא. וְעוֹד נִמְצָא בְּמִצְוָה זוֹ תּוֹעֶלֶת רַבָּה לְהַשְׁבִּית רִיב וּלְהַעֲבִיר הַמַּשְׂטֵמוֹת מִלֵּב בְּנֵי אָדָם, וּבִהְיוֹת שָׁלוֹם בֵּין אֲנָשִׁים יַעֲשֶׂה הַשֵּׁם יִתְבָּרַךְ שָׁלוֹם לָהֶם.
To not avenge: To not avenge, meaning to say that we have been prevented from taking revenge from an Israelite. And the content is, for example, that an Israelite did evil or caused pain to his fellow in one of the things that it is customary among most people to not veer from searching for the one who did evil do them until they pay him back like his evil deed, or they hurt him like he hurt them. And God, may He be blessed, has prevented us from this matter, by His stating (Leviticus 19:18), “You shall not avenge.” And the language of Sifra, Kedoshim, Chapter 4:10 [is] “How far is the power of revenge? If [one] said to [another], ‘Lend me your sickle,’ and he did not lend him. The next day [the other] said to him, ‘Lend me your spade.’ [So] he said [back], ‘I will not lend you [it], just as you did not lend me your sickle.’ Hence, it is written, ‘You shall not avenge.’” And compare like this to all things. It is from the roots of the commandment that a person know and put into his heart that everything that happens to him — good and bad — the cause of it coming to him is from God, blessed be He. And from the hand of man — from the hand of a man to his brother — there would not be anything without the will of God, blessed be He. Hence, when a person caused him pain or hurt him, he should know for himself that his [own] sins caused [it], and that God, may He be blessed, ordained this for him. And he should not place his thoughts to taking vengeance from [the one who pained him], since he is not the cause of his evil, but rather the sin is the cause; like David, peace be upon him, stated (II Samuel 16:11), “leave him to curse, since the Lord told him [so]” — he made the matter depend upon his [own] sin, and not upon Shimei ben Gera. And there is also a great benefit found in this commandment, in quieting a dispute and removing enmity from the heart of people. And when there is peace among people, God, may He be blessed, will make peace for them.