Sage Gautam was one of the profound sages of that era and a great intellectual. He was the composer of 'Dharmsutra', book that directs mankind about justice as well as guiding them about dharm and adharm. Like I informed in my last post; he was an stoic, a jitendriya(the one who has won all his senses) and hence was eligible of such composition.
But, we must also cognize that he wasn't a trikaaldarshi, an omniscient(one who can look into past, present and future) and so was unaware of Indra's plot.
ShriRamavtaar was a prophecy that was in cognizance among the divine beings and so he knew about it. He decided such chastisement for Ahilya keeping in his mind about her chastity and so opened a way to liberate her and who better than Shri Ram, Narayarn himself could have done so and that is what he did.
When Shri Ram arrived at the hermitage accompanied by sage Vishwamitra and Lakshmarn, the sage informed him about the unfortunate that occurred. With his directions, Shri Ram entered the hermitage. They found Ahilya in austerity, glistening with her tapashcharya, it’s just that no one was able to see her, such was the impact of the great curse that lady was enabled to.
Between all this happened what happened to the prime culprit, INDRA. Well he was left testicle-less after Gautam cursed him, he went to his abode where with the help of other devas, a lamb's testicle were arranged and Indra was healed.
Big question; he was the main accused, how could he be freed so easily while Ahilya, who was innocent, if given a thought, suffered for centuries.
No, certainly not so. The punishment that Indra got was a lot more severe, he was humiliated and held in detention for days by a young rakshas prince years later in an epic war. In spite of being capable, it were his deeds that he lost and even today he is condemned for his immoral act while Ahilya is praised.
"No matter how far or farther you go, KARMA follows"