After David completed setting up the tent and the box, he held a celebration. He and the people would be able to connect with God more easily and more frequently.
(Although, God is everywhere and near everyone who calls on him, Israel had gotten used to the tent and the box being the focal point of the connection with God. It was a mental construct they had gotten attached to, and may have moved toward a fuller communion with God, if history had been different. However, many may have met with God unconstrained by religious rules.)
As part of the celebration, David wrote a song and formed a band to sing it. In the song, David describes the trees exulting in joy, because God will judge the earth!
Judgement and joy are not usually associated together. We usually associate fear or dread with judgment. We would only be joyful in judgment if we expected the forces of judgment to be like the cavalry. The cavalry is a symbol in american movies of rescue, restoration and victory. And that's how Israel viewed judgment. There was a lot wrong with the world. Evil was rampant. People were oppressed. manipulated, taken advantage of, abused, and just not treated very nicely. But God was coming. He was going to set everything right. Bad people were not going to hurt anyone anymore. Good people were going to be recognized. All the flaws, inequalities and problems in the world were going to be set right.
Punishment is part of the equation in judgment. those waiting earnestly for God's coming rejoice because they are confident of their relationship with God. Their focus is the good coming into the world because of God's judgment.
NOTE: Part of the joy in the judgment of sin is the realization that the presence of God will not be limited. The mission of Satan and his demonic army is to diminish God's glory and to make people miserable. People experience joy when they fulfill their design ... including fellowship with God. With the removal of evil, people can experience God's presence with greater intensity, more continuously and more purely.