Why did God create the world?
Because God's attributes are living and show themselves. Just as a flower shows its colours and fragrance, God shows Himself in His creation, and He wished to be known.
Why does a flower have a fragrance, and why does it glow in so many colours? Because that is part of its nature. Take away its scent and colour, and it is no longer a flower. In the same way a person speaks because they are able to speak. Someone who never speaks, though they could, lets that ability die within them.
It is similar with God. He has attributes. He is the Creator, the Merciful, the Wise. Attributes are only alive when they show themselves. A Creator who never created anything would not be a living Creator. The world is therefore the expression of the living God. His attributes appear in it, as the second verse above says.
There is a second side to this. What no one knows is, for everyone else, as if it did not exist. Think of a beautiful flower in the middle of the desert that no person and no animal ever sees. We would feel sorry that so much beauty goes unnoticed. God is the source of all beauty. He did not wish to remain unknown, and so He created beings who are able to know Him.
That is why the Holy Qur’an names serving God as the purpose of human life. Serving presupposes knowing. Whoever comes to know God meets His beauty and goodness, and that enriches the person, not God.
Creation is therefore neither an accident nor a pastime. It is God revealing Himself, and human beings are invited to read it and to find their Creator in it.