All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Perhaps you are referring to the Hadeeth narrated by Muslim in his Saheeh on the authority of Abu Sa`eed al-Khudri that the Prophet said: “A man should not look at the 'Awrah of another man, and a woman should not look at the 'Awrah of another woman, neither should two men lie naked under one cover, nor should two women lie naked under the same cover.”
An-Nawawi said when explaining this Hadeeth: (As for his saying: “… neither should two men lie naked under one cover…”, as well as a woman with a woman, then this dislikeability means prohibition if there is no barrier between them, and there is evidence that it is forbidden to touch the ‘Awrah of someone else regardless of which part from his body it is, and this is agreed upon.” [End of quote]
The wisdom in that is to block the reason that may lead to falling into immorality. Al-Madhhari said in al-Mafaateeh fi Sharh al-Masaabeeh: “Meaning: It is not permissible for two men to lie naked under one cover; because if a man’s skin touches the other man’s skin, then it is not safe that their lust will be incited and the appearance of immorality between them; likewise is the case with two women, if the skin of one of them touches the other one’s skin, it is not safe that their lust will be incited and the appearance of immorality between them.” [End of quote]
Allah knows best.