In The Name of Allaah, The Most Merciful, The Bestower of Mercy.
Allaah [The Most High] said:
سَيَقُولُونَ ثَلَاثَةٌ رَّابِعُهُمْ كَلْبُهُمْ وَيَقُولُونَ خَمْسَةٌ سَادِسُهُمْ كَلْبُهُمْ رَجْمًا بِالْغَيْبِ ۖ وَيَقُولُونَ سَبْعَةٌ وَثَامِنُهُمْ كَلْبُهُمْ ۚ قُل رَّبِّي أَعْلَمُ بِعِدَّتِهِم مَّا يَعْلَمُهُمْ إِلَّا قَلِيلٌ ۗ فَلَا تُمَارِ فِيهِمْ إِلَّا مِرَاءً ظَاهِرًا وَلَا تَسْتَفْتِ فِيهِم مِّنْهُمْ أَحَدًا
[Some] say they were three, the dog being the fourth among them; (others) say they were five, the dog being the sixth, guessing at the unseen; (yet others) say they were seven, the dog being the eighth. Say (O Muhammad): “My Lord knows best their number; none knows them but a few.” So debate not (about their number, etc.) except with the clear proof (which We have revealed to you). And consult not any of them (people of the Scripture) about (the affair of) the people of the Cave. [Surah Al-Kahf. Aayah 22]
Allaah informed (us) of the differing between the people of the scripture regarding the number of the people of the cave- a differing out of guessing at the unseen, forging statements and speaking about that which they have no knowledge. Some of them said that the people of the cave were three in number and their dog was the fourth, and others said that the people of the cave were five in number and their dog was the sixth. Allaah said that these two statements are tantamount to guessing at the unseen, so this indicates that they are false. And amongst them were those who said that the people of the cave were seven in number and their dog was the eighth. This statement-and Allaah knows best- is what is correct because Allaah declared the first two statements false but did not declare this third one to be false, so this indicates that it is correct.
This differing is one that neither carries any benefit nor are the people benefited by knowing the number of the people of the cave. It contains neither a benefit related to religion nor the worldly affairs and that is why Allaah stated: [قُل رَّبِّي أَعْلَمُ بِعِدَّتِهِم مَّا يَعْلَمُهُمْ إِلَّا قَلِيلٌ ۗ – Say (O Muhammad):My Lord knows best their number; none knows them but a few]; and they are those who know what is correct and known for being upon what is correct.
[ فَلَا تُمَارِ فِيهِمْ إِلَّا مِرَاءً ظَاهِرً -So debate not (about their number, etc.) except with the clear proof (which We have revealed to you)] based upon knowledge, certainty and about that which contains benefit. As for debating based on ignorance and guessing at the unseen or about that which has no benefit- either the debater being obstinate or the affair being debated having no benefit- neither any religious nor [praiseworthy] worldly benefit, such as the number of the people of the cave and what is similar to it- then too much debate about it and continuous research regarding it is a waste of time, and it makes the hearts have a strong love for that which has no benefit. [وَلَا تَسْتَفْتِ فِيهِم مِّنْهُمْ أَحَدً – And consult not any of them (people of the Scripture, Jews and Christians) about (the affair of) the people of the Cave] because their speech regarding it is based on guessing at the unseen and conjecture can be of no avail against the truth.
This [Ayah (i.e. 18:22)] proves that it is not permissible for a person to issue a verdict when he is not worthy of it- either due to his inability to issue a verdict in that affair or due to fact that he does not care what he says about the affair because he does not possess that fear of Allaah that will stop him from speaking about affairs that are unclear to him, which may harm him in the afterlife. So when it is the case that he has been forbidden from giving verdicts in the likes of this affair, then prohibiting him from giving verdicts [in general] is of a greater prohibition. Also this ayah proves that a person maybe prohibited from giving a verdict in some affair but not in other affairs, so he gives a verdict in that which he is worthy of giving a verdict and not in other affairs because Allaah has not prohibited him from giving a verdict completely; rather they were prohibited from giving a verdict regarding the affair of the people of the cave and what is similar to it. [An Ecerpt from Tayseer Al-Kareem Ar-Rahmaan Fee Tafseer Kalaam al-Mannaan’. slightly paraphrased]