The Qur’an in Chapter 51 verse 56, says that God created humans to worship or serve Him. Whereas, in Chapter 11 verse 119, it defines the purpose of creation as mercy or eternal bliss. We also find that in Chapter 7 verse 179, God says that the purpose of creation is hell for a large number of people. Notice that the verse 7:179 does not define the purpose of creating hell but the purpose of creating jinn and humans. The verse says: Certainly, We have created for hell, many of the jinn and humans. The verse does not say: Certainly, We have created hell for many of the jinn and humans.
There is no contradiction between the verses quoted above because there are two aspects to the purpose of an action: (1) The perfection of the action (2) The end where the action leads to.
To understand this better, we can use the example of a carpenter who intends to build a door which is the ultimate perfection or goal of his action. From another angle, he knows that not all the lumber can be turned into a door. That is why there will inevitably be some waste in the process which is included in his objective from the start. This is called “purpose of necessity”. Therefore, we can say that the carpenter has two purposes with respect to the lumber at his disposal: (1) To make a door which is the perfection of his action (2) To convert some of the lumber into a door and throw out the rest as waste which is the end where the action leads to.
Coming back to the purpose of creation, we can now say that God’s primary will was to create human beings so that they may serve Him and thus enter His mercy which is human perfection and felicity. But the life of this world with its opposing causes and forces does not permit all species to pursue their real goal and this fact is in the knowledge of God even before creation. Therefore, there is a second purpose which is the secondary will of God to take the wretched individuals to hell even though He created them for His mercy or paradise. What is mentioned in the verse, Certainly, We have created for hell, many of the jinn and humans relates to the secondary will of God whereas, the verse except those on whom your Lord has mercy – and that is why He created them (11:119) relates to the primary will of God with respect to creation.
Reference: Al-Mizan English Volume 16, pp 223-224, first edition, Tawheed Institute Australia Ltd, 2018.