The question that why did Allah create humans (or anything at all) can be approached in two ways:
1- Based on what Allah revealed in the scripture(s).
2- Philosophical reasoning
I’d leave the one based on revelations from Allah to religious scholars to explain.
Philosophical approaches to this question go like this. If there is a Creater, He/She would face a choice to use power to create or not. When it is presented as a choice, decision to create can be considered an act of benovelance to bring other beings especially conscious ones into existence to be able to experience both existence and creation.
It then becomes a demonstration of creative, moral, and aesthetic values; power of knowledge and value of wisdom, need for balance and justice, comparison of good and evil and so on. It becomes an exhilarating experience of manifestations of intellect, beauty, and profound pleasures.