This teaching was given by the Supreme Buddha while he was living in Veḷuvana monastery.

Queen Khemā was the wife of King Bimbisara. Because of merit done in the past, she was extremely beautiful. But she had heard that the Buddha criticized being beautiful. Because of this, she never went to the monastery to listen to the Dhamma. The king, knowing that she was very attached to her own beauty, had someone write songs telling how beautiful the Veḷuvana monastery was. Then he had professional singers perform these songs for the queen.

As Khemā listened to the songs sung by these singers, Veḷuvana seemed to her like a place she had never seen before or heard of before. “What park are you singing about?” she asked the singers. “Your majesty, we are singing about your own monastery Veḷuvana,” they replied. Right away she wanted to go to the monastery. The Buddha, knowing that she was coming, created an image of a woman who was extremely beautiful, standing at his side and fanning him with a fan.

When Queen Khemā entered and saw that woman, she thought to herself, “I have always been told that the Supremely Enlightened One criticizes beauty. But here next to him stands a woman fanning him. I don’t have even a sixteenth part of her beauty. Indeed, I have never seen so beautiful a woman before. People who say the Buddha criticizes beauty must be wrong.” And hearing not even the sound of the Buddha’s voice as he preached the Dhamma, she stood there, string at that woman.

The Buddha, noticing how much she thought of this image, transformed the image from a woman of youth and beauty into a decrepit old woman. Then he finally made her into just a pile of bones. Khemā, seeing her, thought, “In but a moment a form even so beautiful as this has broken down and died. Indeed there is nothing permanent in this material form!” The Buddha read her mind and said to her, “Khemā, in the past you wrongly thought, ‘Beauty is so important.’ Look now how this changes!” So saying, he taught her the Dhamma and she became a stream enterer, a sottapanna.

Then he preached this verse:

347. Those who are obsessed with passion and have fallen into the flood of craving, are like a spider, caught in its own web. This, too, the wise cut off. In order to abandon all suffering, without any longing for sense pleasures, wise people become monks and nuns.

At the conclusion of the lesson Khemā became an arahant. And the rest of the crowd also benefited from the sermon.

Then the Buddha told the king, “Great king, Khemā ought either to become a bhikkhuni (a nun) or attain final Nibbāna passing away.” The king replied, “Reverend Sir, please allow her to become a bhikkhuni and become part of the Sangha.” She then became a bhikkhuni and was the Buddha’s wisest bhikkhuni disciples.