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.