Isaiah 24:22

And they shall be gathered together, as prisoners are gathered in the pit, and shall be shut up in the prison, and after many days shall they be visited.

The verse describes the wicked, including the high powers and the kings of the earth punished by the Lord, being gathered together as prisoners are gathered in a pit and shut up in the prison. They are confined like prisoners awaiting their fate, held together under judgment rather than left free. Their gathering includes both exalted powers and earthly rulers brought low under the Lord's punishment.

Being visited after many days means being brought out for judgment to face the execution of the judgment written. The visiting is not mercy but summons, when the confined are led forth to receive their sentence.

This is fulfilled at the close of the thousand years, when the wicked are raised in the second resurrection. The many days are the thousand years of confinement, ending when the dead wicked are raised to stand before God.

Their confinement comes before the Lord's glorious reign in Zion and Jerusalem. The gathering into the pit and prison precedes that reign, with the visitation following after the long interval.