Answer:
By defeating the Pokemon league (that is the elite four +the champion)
Actually, you have to get the Azure Flute from a Nintendo Wifi Mystery Gift Event. So, you'll have to get as far into the storyline as possible. This also means getting the Secret Key, Member Card, etc., from the same source. Set up your Nintendo WFC Settings from the Title Menu, then from the same menu, select "Mystery Gift", "Receive Gift", and then "Nintendo WFC". Then, go to a Pokemon mart (any one but the Pokemon League) and pick it up. It will be under "Key Items". Go to Spear Pillar after stocking up on EVERYTHING YOU WILL NEED, then stand on the tile with a flute on it. Save the game before challenging the god of Pokemon, Arceus.