Interesting question with an interesting answer.
How did Peter know Elijah and Moses at the transfiguration?
Among other places Malachi had prophesied that Elijah would appear before the coming of the Lord. Jesus picks up this same prophecy and points to John the Baptist as the fulfillment.
And he shall turn the heart of the fathers to the children, and the heart of the children to their fathers, lest I come and smite the earth with a curse.
In another place, Jesus speaks of
And if ye will receive it, this is Elias, which was for to come. For all the prophets and the law prophesied until John.
So, what about the transfiguration?
And, behold, there appeared unto them Moses and Elias talking with him.
Moses represented the Law and Elijah (Elias) the prophets. Peter knew this. They were to continue until Christ. They weren't to be abolished, but fulfilled. Christ was the end of the Law and the fulfillment of the prophecies.
The point of the transfiguration is Peter correctly understood the two figures as the Law and Prophets, but along with Christ mistakenly wanted to maintain that order; he wanted to build three tabernacles as if they would be permanent fixtures. God instead opens the heavens and speaks to them and corrects them.
While he [Peter] yet spake, behold, a bright cloud overshadowed them: and behold a voice out of the cloud, which said, This is my beloved Son, in whom I am well pleased; hear ye him.
Listen to Jesus Christ. He alone remains, having fulfilled all that Moses (law) and Elijah (prophets) had required.