"And I did not create the jinn and mankind except to worship Me," meaning: that they might acknowledge My servitude, according to the Tafsir of Ibn 'Abbas.
Yahya said: This is like His saying, "And if you ask them, 'Who created them?' they will surely say, 'Allah.'"
﴿وَمَا خَلَقْتُ الْجِنَّ وَالإِنْسَ إِلا ليعبدون﴾ أَي: ليقروا لي بالعبودية فِي تَفْسِير ابْن عَبَّاس.
قَالَ يحيى: كَقَوْلِه: ﴿وَلَئِنْ سَأَلْتَهُمْ مَنْ خَلَقَهُمْ ليَقُولن الله﴾