Escaping Twilight Town in Kingdom Hearts II is mostly a matter of progressing the story. If you're still playing as Roxas, keep going until you gain control of Sora.
Once you're able to play as Sora, head to the train station and board the train. That'll take you out of Twilight Town and onward with the adventure.