What is the punishment for this? I always heard about what the punishment will be for it, if I penetrate someone, but what if someone just sleeps with the opposite sex (without penetration), how will he/she get punished?
There is no specific punishment for this act (sleeping with someone without having intercourse) in the dunia, as punishment was only mentioned for those who commit fornication (intercourse). However, Allah might keep the punishment until the hereafter unless the sinner repents sincerely, as repentance deletes what's before. And Allah knows best.
All Praise to Allah Subhan o Taala and blessings on Prophet Muhammad peace be upon him His family and companions
As you have asked
but what if someone just sleeps with the opposite sex (without penetration),It is a great sin and not allowed in Islam ,,one must sincerely repent and do Tawbah.
.......The food (slaughtered cattle, eatable animals, etc.) of the people of the Scripture (Jews and Christians) is lawful to you and yours is lawful to them. (Lawful to you in marriage) are chaste women from the believers and chaste women from those who were given the Scripture (Jews and Christians) before your time, when you have given their due Mahr (bridal money given by the husband to his wife at the time of marriage), desiring chastity (i.e. taking them in legal wedlock) not committing illegal sexual intercourse, nor taking them as girl-friends.....Quran Al-Maida 5:5
It is not allowed in Islam to make any kind of relationships or hanging around and sleeping with Non Mahram and as the question says if someone just sleeps indicating not sure if may be once or more it could lead to intercourse as well so should stop doing this way of destroying duniya o akhirah.
Abu Hurairah (May Allah be pleased with him) said: The Prophet (ﷺ) said, "Allah has written the very portion of Zina which a man will indulge in. There will be no escape from it. The Zina of the eye is the (lustful) look, the Zina of the ears is the listening (to voluptuous songs or talk), the Zina of the tongue is (the licentious) speech, the Zina of the hand is the (lustful) grip, the Zina of the feet is the walking (to the place where he intends to commit Zina), the heart yearns and desires and the private parts approve all that or disapprove it."
[Al-Bukhari and Muslim].
So whosoever does good equal to the weight of an atom (or a small ant), shall see it.And whosoever does evil equal to the weight of an atom (or a small ant), shall see it. Quran 99:7-8
Allah Swt and His Messenger knows best.