O Messenger of Allah, the Children of Israel were more honored by Allah than we are. Whenever one of them sinned, the expiation for his sin would be written upon the threshold of his door: ‘Cut off your nose and your ear; do such-and-such.’ The Messenger of Allah, may Allah bless him and grant him peace, fell silent, whereupon Allah, Exalted is He, revealed this verse. (1)
Ata' said: It was revealed concerning Nabhan the date-seller, whose kunyah was Abu Ma'bad. A beautiful woman came to him to buy dates, and he said to her, “These dates are not of good quality; I have better ones in the house.” He took her to his home, drew her close to himself, and kissed her. She said to him, “Fear Allah!” So he left her, regretted what he had done, and came to the Prophet, may Allah bless him and grant him peace, and told him about it. Then this verse was revealed. (2)
Muqatil and al-Kalbi said: The Messenger of Allah, may Allah bless him and grant him peace, established a bond of brotherhood between two men, one from the Ansar and the other from Thaqif. The Thaqafi went out on a military campaign and entrusted the Ansari with the care of his family. One day, the Ansari bought meat for them. When the woman came to take some of it, he entered after her and kissed her hand. He then regretted it, went away, scattered dust upon his head, and wandered aimlessly. When the Thaqafi returned, the Ansari did not come out to greet him. So he asked his wife about him, and she said, “May Allah not increase the likes of him among brothers,” and described what had happened.
Meanwhile, the Ansari was roaming through the mountains, repenting and seeking forgiveness. The Thaqafi searched for him until he found him, then brought him to Abu Bakr, hoping that he would find with him comfort and relief. The Ansari said, “I am ruined,” and related the story to him. Abu Bakr said, “Woe to you! Did you not know that Allah is protective of the one who goes forth to battle in a way that He is not protective of one who remains behind?” Then the two of them went to Umar, may Allah be pleased with him, and he said the same. They then came to the Prophet, may Allah bless him and grant him peace, and he said to him the same as they had said. Thereupon Allah, Exalted is He, revealed this verse: “And those who, when they commit an indecency...” (3)
That is, an ugly deed that falls outside what Allah, Exalted is He, has permitted. The root meaning of indecency is ugliness and transgression beyond the proper bounds. Jabir said: “The indecency is fornication.”
“Or wrong themselves”: this refers to acts short of fornication, such as kissing, embracing, looking, and touching.
Muqatil and al-Kalbi said: The indecency refers to acts short of fornication, such as a kiss, a touch, or a glance at that which is unlawful; or they wrong themselves through disobedience.
It was also said: They commit the indecency of major sins, or wrong themselves through minor sins.
And it was said: They commit an indecency in deed, or wrong themselves in speech.