First, finish the game with every team. Once you have done that, a new stage appears, I believe on the team selection screen.
There is a second requirement too: you need all seven Chaos Emeralds. It does not matter which team you collect any of them with. With both conditions met, the Metal Sonic battle unlocks.