The Messenger of Allah ﷺ said that when Sulayman bin Dawud ﷺ built Bayt al-Maqdis, he asked Allah for three things. He asked Allah
for judgment that would align with His judgment, and he was granted it. He asked Allah
for a kingdom that would not be fitting for anyone after him, and he was granted it. And when he finished building the mosque, he asked Allah
that no one come to it intending nothing but prayer within it, except that Allah would cleanse him of his sins, leaving him as on the day his mother bore him.
أخبرنا عمرو بن منصور قال حدثنا أبو مسهر قال حدثنا سعيد بن عبد العزيز عن ربيعة بن يزيد عن أبي إدريس الخولاني عن ابن الديلمي
عن رسول الله ﷺ أن سليمان بن داود ﷺ لما بنى بيت المقدس سأل الله عز وجل خلالا ثلاثة سأل الله عز وجل حكما يصادف حكمه فأوتيه وسأل الله عز وجل ملكا لا ينبغي لأحد من بعده فأوتيه وسأل الله عز وجل حين فرغ من بناء المسجد أن لا يأتيه أحد لا ينهزه إلا الصلاة فيه أن يخرجه من خطيئته كيوم ولدته أمه
It is in Sunan al-Kubra, no. 772. Ibn Majah and others also narrated it, no. 1408, through another route from Fayruz bin Daylami with the same wording. Ibn Khuzayma graded it sahih, 22/288, no. 1334, as did Ibn Hibban (al-Ihsan), no. 633.