Allah(swt) is independent and doesn’t need us. If he didn’t create the universe for no reason. He told us we were created to pray and we are in need of him and we pray to benefit ourselves. Why did Allah(Swt) create us to worship him?

Allah created us to worship Him so we benefit and experience his mercy. So it’s out of his mercy