This is the other side of the Mercies of David concept which requires servitude to God’s people and the unsaved as a result of having our sins and failings managed by God.
God is able to turn a negative situation into something good. The restoration of joy allows Christians to focus on their calling and is part of the covenant promise.