Human society is deeply shaped by the moral character of the individuals living within it. The overall well-being of a community relies on the success of good people, just as the removal of harmful individuals is necessary for the world to function properly.
When God grants success and good fortune to the righteous, the entire city rejoices [אבן עזרא]. The primary approach among commentators is that this public joy occurs because the righteous are genuinely loved by others. More importantly, they do not keep their success to themselves. Instead, they actively work for the public good, establish social order, and share the material wealth God has given them with the rest of the community through acts of charity and kindness [אלשיך, מלבי״ם, מצודת דוד, עמנואל הרומי, אמרי דעת].
Conversely, when wicked people lose their power or perish, a different kind of joy emerges [ביאור שטיינזלץ]. During their lives, these individuals actively harmed those around them, corrupted leadership, and acted purely out of selfishness [רלב״ג, מלבי״ם, מצודת דוד]. Therefore, their downfall does not disrupt the order of the world; rather, it actively sustains it. Just as a person pulls weeds and thorns from a vineyard to allow the vines to bear fruit and thrive, removing corrupt elements from society allows the community to exist in a state of blessing and joy [עמנואל הרומי].