An anomaly cage was a machine constructed by the Cult of the Heretic. Its function was to allow its user to "regenerate" the universe and start anew in the user's image. It needed a Time Lord to use it.
After the Heretic was taken by the Time Lords, the Cult needed another Time Lord to activate the cage. They made a deal with the Master, who had come to offer them his DNA in return for a position of power in their recreated universe. They manipulated him into coming into contact with his past self, claiming that they wanted him to kill his past self to prove his dedication to their cause. After the Master had crippled his past self, the Cult betrayed the Master by knocking out the future Master and transferring the past Master into his future self, leaving the older Master's mind in his past self. The Cult's intention was to kill the older Master in his past self and thus use the resulting paradox to unmake the universe, but the plan was interrupted when the future-in-past Master managed to escape.
After the two Masters had established the situation and returned to their normal bodies, they returned to the Cult's headquarters and killed all of the members. They planned to use the anomaly cage to recreate the universe but were stopped by the Seventh Doctor, who had managed to escape the destruction of the rest of the universe and track the Masters to the Anomaly Cage. Having disabled the Masters using weapons they had previously discarded, the Doctor then made sure that the universe remained practically unchanged by its regeneration, his only change being to save the life of his temporary companion Jemima so that she was never killed by the Master and send the two Masters back to wherever they had been before they came in contact with the Cult with no memories of this experience. (AUDIO: The Two Masters)