A quick thought that I once had. Rav Hirsch in his commentary to the 24th Psalm, explains the repetition and nuance of the last few verses:
Seu She’arim Rasheichem – Let the gates lift their heads
Vehinasu Pischei olam– Let the portals of the world be raised up
Veyavo Melech Hakovod– and the Glorious King shall come.
Mi zeh Melech… “Who is this Glorious King? Hashem the strong and mighty, Hashem Mighty in War”
Hirsch explains: “At first, however, the gates of human society do not heed this call to open out of their own free will…therefore Vehinasu- “be lifted up…by an external force”…”The L-rd reveals himself in history first by means of shattering, catastrophal occurences”
But then again the Psalmist declares:
Seu Shearim Rasheichem; “Let the gates lift their heads..And let the portal rise up”
This time, the portals of humanity, the hearts of mankind are not lifted up by external forces, by the mighty warrior G-d. But they raise themselves of their own initiative to allow Hashem’s presence to fill the world.
The Psalm ends, “Who is the glorious King? Hashem, Lord of Hosts is the glorious King!”
Hirsch is foretelling an episode in history in which Hashem will reveal himself through might, but it will not suffice. Mankind will need to accept Hashem from internal recognition, and not through fear.
A similar scenario is depicted in the Ramban in this week’s Parsha.(31; 17-18)
The prophetic verses talk of the Jewish people turning to Hashem in their darkest hour and contritely admitting that their troubles came because Hasem was not “within them”.
Then, instead of being saved, Hashem promises to further hide his countenance until they repent. Ramban calls this period in history “Hester Pnei Hageulah”, a hiding of the imminent salvation. (We don’t know if he is describing a period of a year a century or a millenium.)
The Ramban explains that the contrite spirit described in the verse was a good start, but was somewhat “superficial”. It was a response to outside forces.
To my way of thinking, Hirsch is describing the events as portrayed in this Ramban, and reading it into Psalm 24. (Rav Hirsch’s commentary in video form here from Legacy Hirsch channel)