What does the biblical account say?
"Slew" in KJV.
The following include the Strong's Concordance numbers for the important word.
[Exo 2:12 KJV] 12 And he looked this way and that way, and when he saw that [there was] no man, he slew[H5221] the Egyptian, and hid him in the sand.
Same word applied to God, here:
[Gen 38:7 KJV] 7 And Er, Judah's firstborn, was wicked in the sight of the LORD; and the LORD slew[H5221] him.
Different word used by his fellow Israelites two verses later in their accusation:
[Exo 2:14 KJV] 14 And he said, Who made thee a prince and a judge over us? intendest thou to kill me, as thou killedst[H2026] the Egyptian? And Moses feared, and said, Surely this thing is known.
Same word applied to God, here:
[Exo 13:15 KJV] 15 And it came to pass, when Pharaoh would hardly let us go, that the LORD slew[H2026] all the firstborn in the land of Egypt, both the firstborn of man, and the firstborn of beast: therefore I sacrifice to the LORD all that openeth the matrix, being males; but all the firstborn of my children I redeem.
The first is more ambiguous than the second, but even the second, being applied to God, must be applicable in a righteous use, right?
And the narrative word is the more accurate, rather than the word used by people in the story to describe the act. Therefore H5221 is the word we should investigate more fully.
So where else is the H5221 word used? How about the verse just prior:
[Exo 2:11 KJV] 11 And it came to pass in those days, when Moses was grown, that he went out unto his brethren, and looked on their burdens: and he spied an Egyptian smiting[H5221] an Hebrew, one of his brethren.
So now, if the word means "murder", then the Egyptian was murdering an Israelite, and defending someone from murder by killing the perpetrator is not murder, it's third-person defense, which is righteous.
That doesn't mean Moses had no fear of the law, because Egyptians would be considered more valuable than Israelites by Egyptian law. And sure enough, Pharaoh, when he heard the news, sought to kill Moses:
[Exo 2:15 KJV] 15 Now when Pharaoh heard this thing, he sought to slay[H2026] Moses.
This gives other options for the second word, i.e., "execute according to law" in retribution for Moses' "crime" of murder. If the second word, H2026, can mean both "murder" (unrighteous) and "execute for murder" (righteous), then even if it applied to Moses' act, it could still be a righteous use.
Bottom line: there's evidence that Moses was righteous in slaying the Egyptian, even if others didn't think he was.