Question: Why is it that in the old testament there is a prophesy that Elijah will return before the Messiah, and Jesus tells his disciples that John the Baptist is Elijah, but John denies that he is Elijah?

Answer: Read all the Bible passages first, my answer follows and references these passages...

Malachi 4:5-6
"See, I will send you the prophet Elijah before that great and dreadful day of the LORD comes. He will turn the hearts of the fathers to their children, and the hearts of the children to their fathers; or else I will come and strike the land with a curse."

Luke 1:13-17
But the angel said to him: "Do not be afraid, Zechariah; your prayer has been heard. Your wife Elizabeth will bear you a son, and you are to give him the name John. He will be a joy and delight to you, and many will rejoice because of his birth, for he will be great in the sight of the Lord. He is never to take wine or other fermented drink, and he will be filled with the Holy Spirit even from birth. Many of the people of Israel will he bring back to the Lord their God. And he will go on before the Lord, in the spirit and power of Elijah, to turn the hearts of the fathers to their children and the disobedient to the wisdom of the righteous-to make ready a people prepared for the Lord."

Matthew 17:10-13
The disciples asked him, "Why then do the teachers of the law say that Elijah must come first?" Jesus replied, "To be sure, Elijah comes and will restore all things. But I tell you, Elijah has already come, and they did not recognize him, but have done to him everything they wished. In the same way the Son of Man is going to suffer at their hands." Then the disciples understood that he was talking to them about John the Baptist.

John 1:19-23
Now this was John's testimony when the Jews of Jerusalem sent priests and Levites to ask him who he was. He did not fail to confess, but confessed freely, "I am not the Christ." They asked him, "Then who are you? Are you Elijah?"

He said, "I am not."

"Are you the Prophet?"

He answered, "No."

Finally they said, "Who are you? Give us an answer to take back to those who sent us. What do you say about yourself?" John replied in the words of Isaiah the prophet, "I am the voice of one calling in the desert, `Make straight the way for the Lord.'"

Matthew 3:1-3
In those days John the Baptist came, preaching in the Desert of Judea and saying, "Repent, for the kingdom of heaven is near." This is he who was spoken of through the prophet Isaiah (Isaiah 40:3-5):

"A voice of one calling in the desert, `Prepare the way for the Lord, make straight paths for him.'"

1 Corinthians 2:14
The man without the Spirit does not accept the things that come from the Spirit of God, for they are foolishness to him, and he cannot understand them, because they are spiritually discerned.

The Old Testament prophecy that Elijah will come before Jesus, was that a prophet would come in the spirit of the Elijah of old. Like him, he would be one with the boldness to stand before the wicked leadership of the day.

Using Scripture to interpret Scripture, Luke 1:13-17 even says that very thing. The angel clearly said that John would be in the spirit and power of Elijah.

The religious rulers of the day couldn't see or understand the spiritual truth. They looked physically for "Elijah". The makes sense in light of 1 Corinthians 2:14. Only those who have God's Spirit can understand spiritual things. In Matthew 17:10-13 Jesus even points out that the rulers did not recognize John as being the spiritual Elijah (even as they did not recognize the spiritual 'son of man' as being the Messiah!). When John (in John 1:19-23) was asked by these very religious (and spiritually blind) rulers if he was Elijah, he answered them truthfully (remembering that they were only thinking physically) that he was not Elijah (in flesh and blood). But to try and point them to the spiritual truth of who he was, John went on to refer them to Isaiah's prophecy (Isaiah 40:3-5 and Matthew 3:1-3) which also spoke of the task that the spiritual Elijah would be carrying out before the coming of Jesus.