Allah is a transcendental entity and possesses all excellences. At the same time, creation is a means of grace and Allah is graceful. His unlimited grace calls for him to create whatever has the potential to be created. Therefore, Allah created because he was graceful, meaning that the reason behind creation lies in his grace and mercy. Moreover, knowing that Allah’s attributes of essence are in oneness with his entity, one can say that the reason behind creation is Allah himself.
Allah created man with two inner calls to good and bad, as well as two outside callers to good and bad, the prophets and Satan, resulting in the potential to reach the highest levels of perfection and also declining to the lowest levels of human value. If man, despite his carnal and satanic desires, takes the path of truth and perfection, then he will be greater than the angels, because they do not have carnal and satanic desires. And if he chooses the path of evil, he will be worse than animals, because they do not have a spiritual aspect like humans do.
If Allah created man with all excellences he could possibly possess, this perfection had not been reached through his free will (making the creation of man in vain). Therefore, the purpose behind man’s creation is only met when he is created with the potential of perfection and when he reaches it through his free will. However, the fact that unbelievers and sinners do not fulfill the true purpose behind creation does not contradict Allah’s reason for creation, because Allah wanted them to have the chance to choose the right or wrong path and reach perfection if they chose to. If Allah made it impossible for man to take the path of evil, then choosing the path of perfection and development would not be through free will either, (and this would contradict the wisdom behind creation).