Luke 9:28 About eight days after Jesus said this, he took Peter, John and James with him and went up onto a mountain to pray. 29As he was praying, the appearance of his face changed, and his clothes became as bright as a flash of lightning. 30Two men, Moses and Elijah, appeared in glorious splendor, talking with Jesus. 31They spoke about his departure, a which he was about to bring to fulfillment at Jerusalem. 32Peter and his companions were very sleepy, but when they became fully awake, they saw his glory and the two men standing with him. 33As the men were leaving Jesus, Peter said to him, “Master, it is good for us to be here. Let us put up three shelters—one for you, one for Moses and one for Elijah.” (He did not know what he was saying.)
Peter knew the identities of Moses and Elijah by a special revelation. A similar revelation is in Matthew 16:
15“But what about you?” he [Jesus] asked. “Who do you say I am?”
16 Simon Peter answered, “You are the Messiah, the Son of the living God.”
17Jesus replied, “Blessed are you, Simon son of Jonah, for this was not revealed to you by flesh and blood, but by my Father in heaven.
The Father revealed this specific knowledge to Peter.