As simple as it sounds, you just keep clearing new stages and you will earn them over time. If you are unsure what they are, Legacy Levels are short stages featuring the flying robots from Sonic Heroes. Your sword is useless there, but your homing attack still works, so rely on that to get through.