What is the purpose of our creation? If it is worship then why does He need our worship?

Allah says:

“And I did not create the jinn and mankind except to worship Me.” Quran 51:56

“[He] who created death and life to test you [as to] which of you is best in deed – and He is the Exalted in Might, the Forgiving “ Quran 67:2

Allah is free of need, yet He creates what He wills.