Unlocking Sonic the Hedgehog in Super Smash Bros. Brawl happens through Adventure Mode, the Subspace Emissary.
Progress to the point where you face Tabuu. During that sequence, Sonic will show up to help you out. After you defeat Tabuu and finish the mode, Sonic becomes a fully playable character, ready to join your roster for regular battles.