"And the name of the slain man of Israel" (Numbers 25:14). Just as the Holy One, blessed be He, occupies Himself with the praise of the righteous in order to publicize them in the world, so does He occupy Himself with the disgrace of the wicked in order to publicize them in the world. Pinchas, for praise — concerning him it is said, "The memory of the righteous is for a blessing" (Proverbs 10:7); and Zimri, for shame — "but the name of the wicked shall rot" (ibid.).
Why the Torah Names Both Zimri and Pinchas
Midrash Tanchuma Buber, Pinchas 3:4
ושם איש ישראל המוכה (שם שם יד). כשם שהקב"ה מתעסק בשבחן של צדיקים לפרסמן בעולם, כך מתעסק בגנותן של רשעים כדי לפרסמן בעולם, פינחס לשבח, עליו נאמר זכר צדיק לברכה (משלי י ז), וזמרי לגנאי, ושם רשעים ירקב (שם).