The 4 republic(class) heroes saves him. But the Emperor allowed it to find the foundry.
Hmmmm... I believe you're confused.
According to Darth Malgus, the Emperor wanted the location of the Foundry but he was never able to get it from Revan, despite having him imprisoned for 300 years. Thus, the plan to let Revan go and having him lead the Empire to the Foundry was devised.
Having done the Jedi Prisoner story-arc, Republic side, we all know better though.