தேவேந்திரன் உருவத்தை மாற்றிக்கொண்டு கௌதம முனிவரின் மனைவியுடன் உல்லாசம் அனுபவிக்கவே தண்டிக்கப்பட்டான்.
Brahma created Ahalya as the most beautiful woman. All the Devas wanted to marry her. Brahma decided that whoever could go around the three worlds first could marry Ahalya. Indra used all his magical powers to go around the three worlds, finally reaching Brahma to take the hand of Ahalya.
However Narada mentioned to Brahma that Gautama had in fact gone around the three worlds even before Indra. Narada explained that as part of the daily puja, Gautama went around the cow at his hermitage. On one of the days when he went around doing his puja, the cow gave birth to a calf. As per the Vedas, the cow at the time of bearing a calf is equal to three worlds; hence Ahalya must be given to Gautama and not Indra. Even though Ahalya was married to Gutama, Indra never forgives his love with Ahalya and waiting for the time to have sex with her.
Rama and Lakshmana first came across the hermitage of Ahalya on their way to Mithilapuri with Sage Vishwamitra. They inquired about the hermitage to the Sage who told them about Ahalya's story. He states that Indra tricked Ahalya into sleeping with him, but was caught by Gautama.
Although early texts describe how Ahalya must atone by undergoing severe penance while remaining invisible to the world and is purified by offering Rama hospitality, in the popular retelling developed over time, Ahalya is cursed to become a stone and regains her human form after she is brushed by Rama's foot.
It is a lesson for everybody in not to have any kind of desire with others wife.