We find in Parshas Shemos that Moshe killed the Egyptian with the name of G-d. Where did Moshe know this from? After all he grew up in Pharaohs palace....
As it says in Malbim Shemot, Moshe was still nursed until the age of 2 by Yocheved, among his people. According to Dvarim Rabbah 11:9, he got prophecy from the age of 3 months, and learned the whole Torah and becoming an exceptional scholar by the time he was returned to Batya at age 2. An angel fed him so he would never have to eat the palace foods (Siftei Cohen Shemot 2:10).
If Moshe hadn't learned it during this time, then he may have learned it at age 20 when he first went out to see his people, and he learned of their suffering (Shemot Rabbah 1:16). In those days, he would teach them Torah, read to them from the book of Iyov and other works on the impending redemption, and he calculated the date of Shabbat so they could keep it etc.
NOTE: As I am in a rush, I haven't double checked the above quoted sources, I am relying on the scholarship of Yosef Deutsch in Let My Nation Go.
This does not answer outright, but the Zohar 120b notes:
בְּגִין דְּמִיּוֹמָא דְּאִתְיְילִיד לָא אַעֲדֵי מִנֵּיהּ שְׁכִינְתָּא
From the day that he was born, the Shechinah (Divine Presence) never left him.
So one can argue that despite growing up in the palace he was still spiritually attuned to a higher world even if he wasn't necessarily aware of it, and thus at the time he needed to use the sheim Hashem it came as he was endowed with this spiritual channel.
The Ari"zal explains elsewhere (Sha'ar HaPesukim, Shemot) that Moshe rabbeinu a"h is directly associated with the level of da'at of Z'eir Anpin, and the holy Name used to kill the Egyptian is found in the reshei tevot of the verse א"ת ה"שמים ו"את ה"ארץ (Bereshit 1:1), thus א"הוה (pronounced Akvah). And this holy Name is associated with da'at as well. Presumably, from the common association with the holy Name, Moshe rabbeinu a"h would intuit that it could be used to punish the evil Egyptian. (See also the Ari"zal, Sha'ar HaPesukim, Emor).
The Leshem, Rabbi Shlomo Elyashiv writes in his Sefer HaDei'ah; Drushei Olam HaTohu (2:255b) that the level of Moshe Rabbeinu was directly from the Ohr HaGanuz, the hidden light. So, just like what the Zohar says that Dov mentioned, Moshe Rabbeinu had a much higher connection with G-d.
On the posuk in Shemos, the Shaloh explains that Moshe's wisdom came from the angel זגנזגל Zagnagael and זגנזגל served as Moshe's teacher.
In other words, he was the source, or מאין, of Moses' wisdom, חכמה.
The Mishnah in Avos says that at the age of forty, one acquires wisdom:
R. Nehemia seems to cite this Mishnah and explains that at the time Moshe Rabbeinu killed the Egyptian, he was of the age forty (Shemos Rabbah 1:29). Thus, Moshe reached forty years old, and according to that principle mentioned in Avos, he possessed wisdom. See also the Leshem mentioned above, that Moshe Rabbeinu was from a much higher level than anyone else. Maybe that somewhat explains the question.
Rashi extracts the answer from a later verse. When Moses returned the next day, he sees two Israelites bickering. Rashi says they are Datan and Aviram, who in the future would lead a rebellion against Moses, alongside the wicked Korach. Moses reproves them—does Israel not have enough enemies that they must fight with each other, too? Indeed, this has been the number one issue plaguing the Jewish people through the ages, and the real source for all of our problems both internal and external. Datan replies: "Do you plan to kill me like you killed the Egyptian?" In Hebrew, the phrasing is hala’argeni ata omer [הלהרגני אתה אמר] "are you speaking to slay me?" From this, Rashi learns that Moses slayed the Egyptian by speaking, having pronounced G-d’s Ineffable Name.
This, of course, brings up a whole new problem: how did Moses know G-d’s Ineffable Name, let alone how to use it so kabbalistically? He was raised among Egyptians, and only just came out to meet his brethren for the first time! Besides, we only read later (in Exodus 6:2-3) that G-d reveals His Great Name to Moses, and tells Moses that He had never revealed the secrets of this Name to anyone before in history. There is no way anyone could have taught it to Moses.
I believe there is one answer, and that it simultaneously answers another question: why does the Torah say Moses was so afraid? Why did he flee? After all, he was the prime minister, and a great general, and could have the Egyptian slain at will.
The Torah tells us that Moses was born entirely good (Exodus 2:2). Rashi cites the Talmud in saying that when he emerged, the entire room filled with light. In fact, according to one opinion, Moses’ birth name, as called by his mother, was Tuviah, literally "G-d’s goodness" (see, for example, Yalkut Shimoni, Shemot 166 or Vayikra 428, as well as Sotah 12a). Moses was born with divine power concealed within him. At that moment when he encountered the evil Egyptian, that latent power suddenly came out of him. G-d’s Ineffable Name shot forth from his mouth-to his own great surprise-and the Egyptian dropped dead. I believe this is why Moses was so afraid. He had no clue where it had come from, and ultimately ran away to discover himself.
Years later, when Moses finally encounters G-d, and G-d reveals His Name, everything comes full circle. Moses finally understands where that power had come from, and Who had given it to him. (Fittingly, Moshe’s name [משה] backwards makes Hashem [השם]—the Name was hidden inside him all along!) He understands why all of these events had to happen; all part of G-d’s plan to prepare him for his final mission. This is very much like Joseph, who experienced tremendous distress before understanding that it was all part of a divine plan.