Overall meaning :
Allah, Exalted be He, mentioned what these youths secretly talked about among themselves and what they resolved to do after abandoning their people: ‘Now that you have left your people and forsaken the false gods they worship other than Allah,’ they said to one another, ‘take refuge in the cave to worship your Lord alone. He will extend to you His mercy by safeguarding your faith for you and protecting you against your people, and He will provide you with means to benefit you in your livelihood and help you find the best way out of your predicament.’
The Almighty mentions some aspects of the protection He afforded them after they had settled in the cave and had been overtaken by a deep sleep: Had you been there, you would have seen the sun, as it rose, inclining away from their cave to the right so that its heat would not disturb them, and as it set, declining away from them to the left, so that its light would not bother them, while they lay in a spacious part of the cave. That is one of the signs of Allah’s immense power and graciousness to His servants. Those whom Allah guides to the truth, like these youths, are indeed rightly guided; as for those He forsakes, you will find no helper for them to guide them to the truth.
Then He describes a wonderful scene of the youths: Had you been there, you would have judged them to have been awake, though they were fast asleep. We turned them over repeatedly in their sleep, to the right side and to the left, while their dog lay at the cave’s entrance with its forelegs outstretched. Had you seen them in that state, you would have surely turned away from them in flight and you would have been filled with terror at their sight.