This Surah takes its name from v. 9 in which the word (Al-Kahf) occurs.
This is the first of those Surahs which were sent down in the third stage of Prophethood at Makkah. We have already divided the life of the Holy Prophet at Makkah into four stages in the Introduction to Chapter VI. According to that division, the third stage lasted from the fifth to the tenth year of Prophethood. What distinguishes this stage from the second and the fourth stages is that during the second stage the Quraish mainly resorted to ridiculing, scoffing, threatening, tempting, raising objections and making false propaganda against the Holy Prophet and his followers in order to suppress the Islamic Movement. But during the third stage they employed the weapons of persecution, manhandling and economic pressure for the same purpose. So much so that a large number of the Muslims had to emigrate from Arabia to Habasha, and those who remained behind were besieged in Shi'ib Abi Talib along with the Holy Prophet and his family. To add to their misery, a complete social and economic boycott was applied against them. The only redeeming feature was that there were two personalities, Abu Talib and Hadrat Khadijah, whose personal influence had been conducive to the support of two great families of the Quraish. However, when in the tenth year of Prophethood these two persons died, the fourth stage began with such severe persecutions and forced the Holy Prophet and all his Companions to emigrate from Makkah.
It appears from the theme of the Surah that it was revealed at the beginning of the third stage when in spite of persecutions and opposition, migration to Habasha had not yet taken place. That is why the story of "Ashab-i-Kahf " (the Companions of the Cave) has been related to comfort and encourage the persecuted Muslims and to show them how the righteous people have been saving their Faith in the past.
This Surah was revealed to answer three questions which the mushriks of Makkah, in consultation with the people of the Book, had put to the Holy Prophet in order to test him. These were: (1) Who were "the Companions of' the Cave"? (2) What is the real story of Khidr? and (3) What do you know about Zul-Qarnain? As these three questions revolved around the history of the Christians and the Jews, and were unknown in Hijaz, a choice was made to test whether the Holy Prophet possessed any source of knowledge of the hidden and unseen. Allah, however, not only gave a complete answer to their questions but also employed the three stories to the disadvantage of the opponents of Islam in the conflict that was going on at that time in Makkah between Islam and disbelief:
While the Quran turned the tables on the questioners who had tried to "expose" the Holy Prophet, in the end of the Surah the same messages have been reiterated that were stated at its beginning: "Tauhid and the Hereafter are absolutely true and real and for your own good you should accept these doctrines, mend your ways in accordance with them and live in this world with this conviction that you are accountable to Allah: otherwise you shall ruin your life and all your doings shall be set at naught."