The short answer is - We are not told. However, we have the following credible possibilities:
The disciples are recorded as hearing :Jesus talking with Moses and Elijah", Matt 17:3, Mark 9:4, Luke 9:30. Therefore, perhaps they heard Jesus say their names as they greeted each other.
They were expecting something like this as per OT prophecies about ...
How did Ezekiel know that certain images were 'cherubim' ? How did John know that a certain image was Diabolos ?
It is part of the gift of a vision to be (also) given the understanding along with the imagery.
Those who have such dreams and visions know the sensation of understanding and interpretation being granted alongside the visionary images.
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 ...