(Exodus 7:1:) "And the LORD said to Moses: See, I have made you a god to Pharaoh." It is written (Psalms 24:7): "Lift up your heads, O gates, and so forth." Who said this verse? Solomon said it. At the time that he made the Ark, he made one Ark of ten cubits, and he carried it to bring it into the House of the Holy of Holies. When he reached the Temple, the entrance was ten cubits, and the Ark was ten cubits, and ten cubits cannot enter within ten; and furthermore, they were carrying it. When he saw that he could not bring it in, he was ashamed, and he did not know what to do. He began to pray before the Holy One, blessed be He. What did Solomon do? He went and brought the coffin of David his father, and he prayed and said (II Chronicles 6:42): "O LORD God, turn not away the face of Your anointed; remember the good deeds of David Your servant." When he mentioned the merit of David his father, immediately he was answered. What is written after it? (II Chronicles 7:1): "And when Solomon had finished praying, the fire came down [from heaven, and so forth, and the glory of the LORD filled the House]." And the Holy Spirit cried out (Ecclesiastes 4:2): "And I praised the dead." Solomon began, he said: "Lift up your heads, O gates." The gates sought at that hour to crush his skull, for they thought that perhaps about himself he was speaking, (Psalms 24:7) "that the King of glory may come in." They said to him (Psalms 24:10): "Who is this King of glory?" He said to them (ibid.): "The LORD of hosts, He is the King of glory. Selah." When he said this to them, they left him alone.
Solomon Opens the Gates by David's Merit to House the Ark
Midrash Tanchuma Buber, Vaera 6:1
ויאמר ה' אל משה ראה נתתיך אלהים לפרעה (שמות ז א). כתיב שאו שערים ראשיכם וגו' (תהלים כד ז), מי אמר הפסוק הזה שלמה אמרו, בשעה שעשה את הארון עשה ארון אחד של עשר אמות, ונשא אותו להכניסו לבית קדשי הקדשים, כיון שהגיע לבית המקדש היה הפתח של עשר אמות, והארון של עשר אמות, ואין עשר אמות יכולות לכנוס בתוך עשר, ועוד שהיו טוענין בו, כיון שראה שלא היה יכול להכניסו היה מתבייש, ולא היה יודע מה לעשות, התחיל להתפלל לפני הקב"ה, מה עשה שלמה הלך והביא ארונו של דוד אביו, והיה מתפלל ואמר ה' אלהים אל תשב פני משיחך זכרה לחסדי דוד עבדך (דה"ב ו מב), כיון שהזכיר זכותו של דוד אביו מיד נענה, מה כתיב אחריו, וככלות שלמה להתפלל והאש ירדה [מהשמים וגו' וכבוד ה' מלא את הבית] (שם ז א), ורוח הקדש צווח ושבה אני את המתים (קהלת ד ב), התחיל שלמה אמר שאו שערים ראשיכם, ביקשו השערים באותה שעה לרוץ את גלגלתו, שהיו סבורין שמא על עצמו הוא אומר ויבא מלך הכבוד (תהלים כד ז), אמרו לו מי הוא זה מלך הכבוד (שם שם י), אמר להם ה' צבאות הוא מלך הכבוד סלה (שם) כיון שאמר להם כך הניחו אותו.