This Surah was revealed in Makkah before the migration to Al-Madinah. The proof of this is what Al-Bukhari recorded from Al-Bara' bin `Azib, that he said, "The first people to come to us (in Al-Madinah) from the Companions of the Prophet were Mus`ab bin `Umayr and Ibn Umm Maktum, who taught us the Qur'an; then `Ammar, Bilal and Sa`d came. Then `Umar bin Al-Khattab came with a group of twenty people, after which the Prophet came. I have not seen the people of Al-Madinah happier with anything more than their happiness with his coming (to Al-Madinah). This was reached to such an extent that I saw the children and little ones saying, `This is the Messenger of Allah ﷺ who has come.' Thus, he came, but he did not come until after I had already recited (i.e., learned how to recite)
سَنُقْرِئُكَ فَلَا تَنسَىٰ ۔ إِلَّا مَا شَاءَ اللَّـهُ (We will make you recite, then you will not forget, except that which Allah wills. Indeed He knows what is manifest and what is hidden....87:6-7). In the preceding verses, Allah depicted the manifestation of His Omnipotence and [ profound ] wisdom. Thereafter, a few guidelines are given to the Holy Prophet ﷺ regarding his prophetic obligation. Before putting forth the guidelines, he is given the cheerful news of making his task easier. When the Qur'an was revealed initially, and as Jibra'il (علیہ السلام) began to recite, the Holy Prophet ﷺ made haste to repeat, lest any word or sentence should be lost. He was, therefore, told not to make haste with it, and to wait until the angel had delivered the whole message, and then to repeat the words of the revelation, being assured that it was a Divine arrangement, and that nothing would be lost. On this occasion, he is still more plainly told: 'then you will not forget, except that which Allah wills.'
It is quite evident that there is planning in the creation of man and the world. This planning strongly implies that there must be some purpose behind this creation. And indeed, this purpose has been revealed to man through divine revelation. However, only that individual learns a lesson from revelation who is of a receptive nature. Such people will be introduced to the eternal bounties of God. But those whose arrogance prevents them from accepting guidance, will be doomed to being cast into the flames of the eternal fire.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.