Parashas Shemos
וַיִּפֶן֙ כֹּ֣ה וָכֹ֔ה וַיַּרְא֙ כִּ֣י אֵ֣ין אִ֔ישׁ וַיַּךְ֙ אֶת־הַמִּצְרִ֔י וַיִּטְמְנֵ֖הוּ בַּחֽוֹל׃
And he turned this way and that and saw that there was no man, and he struck the Egyptian and hid him in the sand.
Torah Temimah points to R’ Chanina — Sanhedrin / TT on 2:12 (verified).
ויך את המצרי — א״ר חנינא: מצרי שהכה את ישראל חייב מיתה, שנאמר ויפן כה וכה וירא כי אין איש ויך את המצרי.
English: “And he struck the Egyptian” — R’ Chanina said: An Egyptian who struck an Israelite is liable to death, as it is said, “And he turned this way and that and saw that there was no man, and he struck the Egyptian.”
Custom
Chazal teach that the Egyptian who was beating a Hebrew had already incurred the death penalty; Moshe acted as an agent of justice.