Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:38:34

And We certainly tried Solomon and placed on his throne a body; then he returned.  

And We certainly tried Solomon: We tested him by wresting his kingdom from him, because he had married a woman ˹solely˺ out of his desire for her. She used to worship idols in his ˹own˺ home without his knowledge. Now, ˹control of˺ his kingdom lay in his ring. On one occasion, needing to withdraw ˹to relieve himself˺, he took it off and left it with this woman of his, whose name was al-Amīna, as was his custom; but a jinn, ˹disguised˺ in the form of Solomon, came to her and seized it from her. And We cast upon his throne a ˹lifeless˺ body, which was that ˹very˺ jinn, and he was ˹the one known as˺ Sakhr — or it was some other ˹jinn˺; he sat upon Solomon’s throne and so ˹as was the case with Solomon˺ the birds and other ˹creatures˺ devoted themselves to him ˹in service˺. When Solomon came out ˹of his palace˺, having seen him ˹the jinn˺ upon his throne, he said to the people, ‘I am Solomon ˹not him˺!’ But they did not recognise him. Then he repented — Solomon returned to his kingdom, many days later, after he had managed to acquire the ring. He wore it and sat upon his throne ˹again˺.
القرآن:٣٨:٣٤

وَلَقَدْ فَتَنَّا سُلَيْمَانَ وَأَلْقَيْنَا عَلَىٰ كُرْسِيِّهِ جَسَدًا ثُمَّ أَنَابَ  

{ولقد فتنا سليمان} ابتليناه بسلب ملكه وذلك لتزوجه بامرأة هواها وكانت تعبد الصنم في داره من غير علمه وكان ملكه في خاتمه فنزعه مرة عند إرادة الخلاء ووضعه عند امرأته المسماة بالأمينة على عادته فجاءها جني في صورة سليمان فأخذه منها {وألقينا على كرسيه جسدا} هو ذلك الجني وهو صخر أو غيره جلس على كرسي سليمان وعكفت عليه الطير وغيرها فخرج سليمان في غير هيئته فرآه على كرسيه وقال للناس أنا سليمان فأنكره {ثم أناب} رجع سليمان إلى ملكه بعد أيام بأن وصل إلى الخاتم فلبسه وجلس على كرسيه.