Sahih al-Bukhari Book 86, Hadith 62
The Prophet (ﷺ) said, "If a lady slave commits illegal sexual intercourse and she is proved guilty of illegal
sexual intercourse, then she should be flogged (fifty stripes) but she should not be admonished; and if
she commits illegal sexual intercourse again, then she should be flogged again but should not be
admonished; and if she commits illegal sexual intercourse for the third time, then she should be sold
even for a hair rope."
The verdict of Allah's Messenger (ﷺ) was sought about an unmarried slave girl guilty of illegal intercourse. He replied, "If she commits illegal sexual intercourse, then flog her (fifty stripes), and if she commits illegal sexual intercourse (after that for the second time), then flog her (fifty stripes), and if she commits illegal sexual intercourse (for the third time), then flog her (fifty stripes) and sell her for even a hair rope." Ibn Shihab said, "I am not sure whether the Prophet (ﷺ) ordered that she be sold after the third or fourth time of committing illegal intercourse."
I asked `Abdullah bin Abi `Aufa about the Rajam (stoning somebody to death for committing illegal sexual intercourse). He replied, "The Prophet (ﷺ) carried out the penalty of Rajam," I asked, "Was that before or after the revelation of Surat-an-Nur?" He replied, "I do not know."