Why did Allah the Exalted create mankind and the jinn?
Answer:
Allah the Exalted says:
«وَمَا خَلَقْتُ الْجِنَّ وَالْإِنسَ إِلَّا لِيَعْبُدُونِ »
Reference: Al-Dhariyat: 56
“And I did not create the jinn and mankind except that they should worship Me.”
I created them so that I may command them to worship Me, not because I have any need of them. «والا ليعبدونه» That is, so that they establish worship of Me in ease and in hardship.