Well, let me explain, Zelda sends Link back in time to when he was about to pull the Master Sword out of it's pedestal and allow Ganondorf to get into the Sacred Realm and thus try and get the Triforce. Link met Skull Kid and taught him the song before he was about to pull the Master Sword out...