It happened, when God helped the Levites who bore the ark of the covenant of Yahweh, that they sacrificed seven bulls and seven rams.
So David gave him the lyrics, and these guys started singing and worshipping the Lord with this song or psalm.