This very question can be expressed in one of the two possible ways...
This very question can be expressed in one of the two possible ways: i) What aim did Allah or the Agent possess in creating His creations, or in other words, what benefit does He wish to avail of by the life and death of man and other creations? If the question is put up in this form, it is necessary to state that the question and its answer is not related to our discussion and it must be deliberated in a discussion related and appropriate to it.
All we can say is that Allah is an Independent Entity, and He avails of no benefit as a result of His creating His creations. Hence, the exact answer for “ Then why did He create?” is related to profound, Gnostic topics. ii) What purpose did Allah or the Agent have for his action? In other words, Allah created His creations and among them man, that they travel along which path and to where they reach or what goal they follow?
In short, Allah created His creations and amongst them, man so that finally they reach the level of cognition of Allah and can understand His Beautiful Attributes and manifest them within themselves, because the real worship and cognizance of Allah can take the creation and man to a position and status, the specialties and the grandness of which must be referred to in gnostical topics.
So according to this view, the philosophy of life and death, which are part of the creation of Allah, become clear. The life and death and basically, the changes in the material world and the transfer from one stage of life to another of it or the transfer from one world into another world, all of these play a part in the journey of man and the creations towards perfection.
Such changes or the ups and downs must be present, in the light of which, people can be tested, and the pure are separated from the unpure.