Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:18:22

They will say there were three, the fourth of them being their dog; and they will say there were five, the sixth of them being their dog - guessing at the unseen; and they will say there were seven, and the eighth of them was their dog. Say, ˹O Muhammad˺, "My Lord is most knowing of their number. None knows them except a few. So do not argue about them except with an obvious argument and do not inquire about them among ˹the speculators˺ from anyone."  

They will say, that is, ˹some of˺ those disputing the number of the youths ˹of the cave˺ at the time of the Prophet (s), in other words, some of these will say that they ˹the youths˺ were: ‘Three; their dog the fourth of them’; and they, some ˹others˺ among them, will say, ‘Five; their dog the sixth of them’ — both of these sayings were those of the Christians of Najrān — guessing at random, in other words, out of supposition, not having been present with them ˹at the time˺, and this ˹statement ‘guessing at random’˺ refers back to both sayings, and is in the accusative because it is an object denoting reason, in other words, ˹they said this˺ for the reason that they were ˹merely˺ supposing it. And they, that is, the believers, will say, ‘Seven; and their dog the eighth of them’ (the sentence is ˹part of˺ the subject clause, the predicate of which is the adjectival qualification of sab‘a, ‘seven’ ˹namely, thāminuhum, ‘the eighth of them’˺ with the additional wāw ˹wathāminuhum˺, which is said to be for emphasis, or an indication that the adjective is ˹semantically˺ attached to that which it is qualifying). The qualification of the first two sayings as being ‘random’, but not the third, is proof that ˹the latter˺ is the satisfactory and correct ˹number˺. Say: ‘My Lord knows best their number, and none knows them except a few’: Ibn ‘Abbās said, ‘I am ˹one˺ of these “few” ˹described˺’, and he mentioned that they were seven. So do not contend concerning them except with an outward manner ˹of contention˺, ˹except˺ with that which has been revealed to you, and do not question concerning them, do not ask for opinions ˹from˺, any of them, ˹from˺ the People of the Scripture, the Jews. The people of Mecca asked him ˹the Prophet˺ about the story of the People of the Cave, and so he said to them, ‘I will tell you about it tomorrow’, but without adding ˹the words˺, ‘If God wills’ (inshā’a’ Llāhu) and so the following was revealed:
القرآن:١٨:٢٢

سَيَقُولُونَ ثَلَاثَةٌ رَابِعُهُمْ كَلْبُهُمْ وَيَقُولُونَ خَمْسَةٌ سَادِسُهُمْ كَلْبُهُمْ رَجْمًا بِالْغَيْبِ ۖ وَيَقُولُونَ سَبْعَةٌ وَثَامِنُهُمْ كَلْبُهُمْ ۚ قُلْ رَبِّي أَعْلَمُ بِعِدَّتِهِمْ مَا يَعْلَمُهُمْ إِلَّا قَلِيلٌ ۗ فَلَا تُمَارِ فِيهِمْ إِلَّا مِرَاءً ظَاهِرًا وَلَا تَسْتَفْتِ فِيهِمْ مِنْهُمْ أَحَدًا  

{سيقولون} أي المتنازعون في عدد الفتية في زمن النبي ﷺ أي يقول بعضهم هم {ثلاثة رابعهم كلبهم ويقولون} أي بعضهم {خمسة سادسهم كلبهم} والقولان لنصارى نجران {رجما بالغيب} أي ظنا في الغيبة عنهم وهو راجع إلى القولين معا ونصبه على المفعول له أي لظنهم ذلك {ويقولون} أي المؤمنون {سبعة وثامنهم كلبهم} الجملة من المبتدأ وخبره صفة سبعة بزيادة الواو، وقيل تأكيد أو دلالة على لصوق الصفة بالموصوف ووصف الأولين بالرجم دون الثالث دليل على أنه مرضي وصحيح {قل ربي أعلم بعدتهم ما يعلمهم إلا قليل} قال ابن عباس أنا من القليل وذكرهم سبعة {فلا تمار} تجادل {فيهم إلا مراءً ظاهرا} بما أنزل عليك {ولا تستفت فيهم} تطلب الفتيا {منهم} من أهل الكتاب اليهود {أحدا} وسأله أهل مكة عن خبر أهل الكهف فقال أخبركم به غدا ولم يقل إن شاء الله فنزل: