Thanks for your question.
The context provides a straight-forward response to this apparent contradiction. Matthew 17:9 And as they were coming down the mountain, Jesus commanded them, “Tell no one the vision, until the Son of Man is raised from the dead.” What the disciples saw was a vision much like the visions of John in Revelation. They did not see the real Moses and Elijah. The word vision in Matthew 17:9 is the same word used in Acts 2:17 – dream dreams and see visions; Acts 10:3 – hath seen a vision; Acts 10:17 – this vision which he had seen; Acts 11:5 – I saw a vision; Acts 16:9 – a vision appeared to Paul; Rev. 9:17 – I saw the horses in the vision. These words are all the same as the one in Matthew 17:9.
Another character whose end appears to be enigmatic is Enoch, who was "translated" that he should not see death - probably at the hands of the sons of Cain. That just means that he was taken out of harm's way and transported by the Spirit to another place... like Philip in Acts 8. The same with Elijah - he was transported to another place to save him from Jezebel. However, many years later, he sent a letter to evil Jehoram King of Judah, prophesying his downfall (see 2 Chronicles 21:12). This indicates that not only was Elijah still alive in "retirement" in a secluded place on earth but that he was kept aware of happenings in Judah and Israel. That's the last we hear of him until the Transfiguration. As we pointed out above, there is no problem with the Transfiguration because the Lord himself, in Matt. 17:9, calls what they saw a "vision."
The vision signified the Lord's fulfillment of the Law (represented by Moses)and the prophets (represented by Elijah). In any case, it was a vision and not a tangible reality. Moses and Elijah were/are dead and await the resurrection to share in the glory of the Messiah. It’s interesting that the word “decease” is, in the Greek, “Exodus.” Jesus was about to embark on the journey which would set all of his people free and lead them, as the forerunner or “firstfruits,” to the promised land, the Kingdom of God.
I hope that helps!
God bless and keep you,