And similarly, We caused them to be found that they [who found them] would know that the promise of Allāh is truth and that of the Hour there is no doubt. [That was] when they1 disputed among themselves about their affair and [then] said, "Construct over them a structure. Their Lord is most knowing about them." Said those who prevailed in the matter, "We will surely take [for ourselves] over them a masjid."2
Translation: Saheeh International (English)
1 The people of the city.
2 i.e., we will make this site a place of worship.
Just as I did those wondrous acts, of putting them to sleep and awakening them after many years, indicating My Power, I caused them to be discovered by the people of their city, so that those people would know that the promise of Allah to help the believers and of resurrection is true, and that the rising is coming without doubt. After the matter of the people of the cave was exposed and they had passed away, those who discovered them differed: What should they do with regard to them? One group said: Build over the entrance of the cave a building that will serve as a barrier and will preserve them. Their Lord knows best about their condition and their condition requires that they have some special status in His sight. The influential people who did not have knowledge or a proper call said: I will set up over them a place of worship in their honour and as a memoir of their location.