Indrajit defeated Indra simply because Brahma punished Indra for his crimes against Ahalya. These stories are highly inspired from Brahmana layers of vedas where Indra lost his position due to killing vritra and visvadevas .
It's directly mentioned in Valmiki Ramayana
- O Vasava! You have been seized by the enemy because of that and not because of any other reason. Control yourself and quickly perform a vaishnava sacrifice. You will go to heaven after you have purified yourself through that sacrifice. O Indra of the gods! Your son has not been destroyed in the great battle. His grandfather has taken him and hidden him inside the great ocean.” Hearing this, the great Indra performed a vaishnava sacrifice. The gods again went to heaven and brought it under their control.
Brahmana layers of vedas also mention why Indra is excluded. The stories of ahalya and indra are inspired by the Brahmana layers of vedas where Prajapati , Rudra and Vishnu surpassed Indra in greatness.
- “I know it from the fact, that Indra had been excluded by the gods (from having any share in the sacrifices). For he had scorned' Visvarupa, the son of Tvastar, cast down Vritra (and killed him), thrown pious men (yatis) before the jackals (or wolves) and killed the Arurmaghas, and rebuked (his teacher) Brihaspati.
- On account of these faults, Indra was forthwith excluded from participation in the Soma beverage. And after Indra had been excluded in this way from the Soma, all the Ksattriyas (at whose head he is) were likewise excluded from it. But he was allowed a share in it afterwards, having stolen the Soma from Tvastar. But the Ksattriya race remains excluded from the Soma beverage to this day.
- 5th chapter, book 7, Aitareya Brahmana.
Puranic legends of Brahma getting beheaded by Shiva’s kalabhairava also comes from the brahmana layers of vedas