According to most exegetes of the Qur'an, a cause of revelation exists for these 16 verses of the Kahf Sureh. From the Qur'an itself, it seems that these verses were revealed because of a question asked from the Prophet by his contemporaries. The Qur'an says: "They will ask you about Zolqarnain. Tell them, 'I will tell you now a tale about him.'"
In the translation of Tabari's History, Bal'ami said that Ibn-e-Abbas had said that when the infidels of Mecca could not contradict the Prophet, they asked for help from the Jews of Khaybar and sent Abu-Djahl to them: "All the Jews came together and brought with them the Torah and extracted three problems from therein." The first question was about the spirit (of course, not the human spirit, but the Holy Ghost, Gabriel). The next question was about the Seven Sleepers, and the third about Zolqarnain: "They told his story, they told how he went from the west to the east and the story of the Ya'jooj and Ma'jooj.
And they said that this was what was told in the Torah, and if Muhammad could answer about what was in the Torah, then we know that he is a prophet."