For clarification are these the ones you referenced?
He was not literally Elijah but came in the Spirit power and authority of Elijah. He came to prepare hearts for Jesus.
And if you are willing to receive it, he is Elijah who is to come. He who has ears to hear, let him hear!
Matthew 11:14-15 NKJV
Now after six days Jesus took Peter, James, and John his brother, led them up on a high mountain by themselves; and He was transfigured before them. His face shone like the sun, and His clothes became as white as the light. And behold, Moses and Elijah appeared to them, talking with Him. Then Peter answered and said to Jesus, “Lord, it is good for us to be here; if You wish, let us make here three tabernacles: one for You, one for Moses, and one for Elijah.”
Matthew 17:1-4 NKJV
This passage is a literal encounter with Moses who represented the law.
And Elijah who represented the prophets of old.
I have always been taught to see context in scripture always read at least 10 verses before and after. It has helped me to see literal, or figurative expression.