Abbas - Tanwîr al-Miqbâs min Tafsîr Ibn ‘Abbâs
(And thou mightest have seen the sun when it rose move away) decline (from their cave to the right) the right of the Cave, (and when it set go past them on the left) the left of the Cave, (and they were in the cleft thereof) on a side of the Cave; it is also said that this means: they were in a space which was reached by the light of day. (That) which I have mentioned of their story (was (one) of the portents of Allah) of the marvels of Allah. (He whom Allah guideth) to His religion, (he indeed is led aright) to his religion, (and he whom He sendeth astray, for him thou wilt not find a guiding friend) who might lead him to the guidance.
Thou wouldst have seen the sun, when it rose, turning aside from their cave to the right.
When the lights of the beginningless secrets show their faces to someone's inwardness, how can the light of the sun of form have the gall to throw its rays upon him or exercise its ruling authority over him? The sun of form is for brightening creation, and the lights of the secret cores are for recognizing the Real. The former is the light of form and the latter is the light of the secret core. The former is the world-brightening sun and the latter the heart-brightening light. The former keeps the world bright so that the creatures may gaze upon it, and the latter keeps the hearts of the friends bright so that the Real may gaze upon them. The lights of the secret cores of those chevaliers in the cave gave out the glittering rays of the lights of the secrets, and the shining sun rolled up its skirt, for it was turning aside from their cave to the right [18:17]. When someone's breast is made the place of the lights of the unseen secrets, his attribute is what the Exalted Lord said concerning these chevaliers:
And you might have seen the sun, when it rose, inclining (read tazzāwaru or tazāwaru) away from their Cave towards the right, side of it, and, when it set, go past them on the left, avoid them and pass over them, so that it does not fall on them at all, while they were in a cavern therein, in an ample space inside the Cave where the coolness and the gentle breeze of the winds reached them. That, which is mentioned, was [one] of God’s signs, [one of] the proofs of His power. Whomever God guides, he indeed is rightly guided, and whomever He leads astray, you will not find for him a guiding friend.
And you might have seen the sun, that is, the sun of the spirit, when it rose, that is, when it rose [in rank] by means of disengagement from the coverings of the body and [when] it emerged manifest from its [the body's] horizons, inclining with them from the direction of the body, its [the spirit's] inclination and love being for the direction of the right, that is to say, the side of the holy world and the path of pious deeds such as acts of goodness, of merit, of virtue and obedience, the conduct of the pious, for the pious are the companions of the right; and when it set, that is, [when] it hurtles down into the abyss of the body and becomes veiled therein and disappears into its darknesses and recesses so that its light is extinguished, it crosses over them and leaves them while they remain on the left, that is to say, [on] the side of the soul and the path of evil deeds so that they become engrossed in acts of disobedience, misdeeds, evil and vices and [follow] the conduct of the profligate who are the companions of the left, while they were in a cavern therein, that is, in a wide space within their body which is the station of the soul and physical nature. For therein is an expanse in which the light of the spirit does not fall on them. Know also that the side of the heart that is adjacent to the spirit is a spot illumined by the light of the spirit and is called the intellect; it is this that summons to good and paves the way to heavenly inspiration. The side [of the heart] that is adjacent to the soul is dark because of the darkness of its attributes and is called the breast; this is the locus for the evil whisperings of Satan, as He has said who whispers in the breasts of mankind [Q. 114:5]. But when the spirit stirs and the heart turns its face to it, it [the heart] becomes illumined, is strengthened by the rational faculty that summons to, and causes yearning for, perfection and inclines to good and obedience. Yet if the soul stirs and the heart turns its face to it, it [the heart] is sullied and is veiled from the light of the spirit, while the intellect becomes dark and inclines to evil and disobedience.
And in both states the angel turns to inspiration and satan to evil whisperings and they mix a righteous deed with an evil one. There is in the verse a subtlety, which is that He uses [the verb] 'to incline away' (izwirār) from the cave in the context of inclining to good and in the context of inclining to evil [He uses the verb] 'cut across' (qaraḍa). That is because the spirit conforms with the heart along the path of good and commands it thereto and accords therewith, turning away from the side of the body and what this [side] conforms with, not according with it along the path of evil. Rather it cuts across it and separates from it while it is engrossed in the darknesses of the soul and those attributes of it that veil it from the light. This is an allusion to variegation in wayfaring. For as long as the wayfarer has not reached the station of fixity and remains in variegation, the soul manifests itself on him together with his attributes so that he becomes veiled from the light of the spirit before returning once again. That, namely, the rising of the light of the spirit and its disappearance, is of God's signs, [the signs] through which the way is found and through which one arrives at Him and His guidance. Whomever God guides, by making him arrive at the station of the witnessing and granting him fixity therein, he indeed is rightly guided, in truth and in no other way, and whomever He leads astray, by veiling him from the light of His countenance, then there will be no one to guide him or direct him [to the right path]. Or it means, and whomever God guides to them [the youths of the cave] and to the truth of their state [is truly guided], and whomever He leads astray, He will veil him from [the truth of] their state.
The Location of the Cave This indicates that the entrance to the cave faced north, because Allah tells us that when the sun was rising, sunlight entered the cave
(the right), meaning that the shade decreased towards the right, as Ibn `Abbas, Sa`id bin Jubayr and Qatadah said:
(declining) means leaning. Every time the sun rises on the horizon, its rays decline until there is nothing left in such a place when it reaches its zenith. So Allah said,
وَإِذَا غَرَبَت تَّقْرِضُهُمْ ذَاتَ الشِّمَالِ
(and when it set, turning away from them to the left,) meaning, it entered their cave from the left of its entrance, which means from the west. This proves what we say, and it is clear to anyone who thinks about the matter and has some knowledge of astronomy and the paths of the sun, moon and stars. If the entrance of the cave faced east, nothing would have entered it when the sun set, and if it faced the direction of the Qiblah (in this case, south), nothing would have entered it at the time of sunrise or sunset, and the shadows would have leaned neither to the right nor the left. If it had faced west, nothing would have entered it at the time of sunrise, until after the sun had passed its zenith, and would have stayed until sunset. This supports what we have said, and to Allah is the praise. Ibn `Abbas, Mujahid and Qatadah said that "turning away from them'' means that it would shine on them and then leave them. Allah has told us this, and He wants us to understand it and ponder its meaning, but He did not tell us the location of this cave, i.e., in which country on earth it is, because there is no benefit for us in knowing that, and no legislative objective behind it. If there was any spiritual or religious interest that could be served by our knowing that, Allah and His Messenger would have taught us about it, as the Prophet said:
(I have not left anything that will bring you closer to Paradise and keep you further away from Hell but I have certainly taught you about it.) So Allah has told us about the features of the cave, but He did not tell us where it is, and He said,
(the right, and when it set, turning away from them to the left, while they lay in the midst of the cave.) meaning, the sun entered the cave without touching them, because if it had touched them, it would have burnt their bodies and clothes. This was the view of Ibn `Abbas.
ذلِكَ مِنْ ءَايَاتِ اللَّهِ
(That is from the Ayat of Allah), how He guided them to this cave where He kept them alive, and the sun and wind entered the cave preserving their bodies. Allah says,
ذلِكَ مِنْ ءَايَاتِ اللَّهِ
(That is from the Ayat of Allah.) Then He says:
مَن يَهْدِ اللَّهُ فَهُوَ الْمُهْتَدِ
(He whom Allah guides, he is the rightly-guided;) meaning that He is the One Who guided these young men to true guidance among their people, for the one whom Allah guides is truly guided, and the one whom Allah leaves astray will find no one to guide him.
Maududi - Sayyid Abul Ala Maududi - Tafhim al-Qur'an
It has not been mentioned that in accordance with this mutual resolve, they left the city and went to a secret Cave in the mountains in order to escape from death or forced apostasy.
This is to show that the mouth of the Cave faced the north. That is why the light of the sun could not enter inside the Cave and the one who passed by it could not see who was inside it.
That is, "If some one could have peeped at the Seven Persons from outside and seen them turning from one side to the other at intervals, he would have thought that they were not asleep but were relaxing themselves."
Allah had so arranged their refuge that none dared go inside the Cave and know about them for it was pitch dark in the Cave and the dog was keeping watch at the entrance. If someone ever peeped into the Cave and saw the Sleepers, he took them for some robbers and at once turned on his heels. This was the reason why their refuge remained a secret to the outer world for such a long period.
…whomsoever He leads astray, you will not find for him a guiding friend.If God wishes to manifest His [prior] knowledge of a person’s ill-fortune (shaqāwa) by lifting His protection (ʿiṣma) from them, you will not find for that person anyone who can protect them from that.His words, Exalted is He: