Very simple. The output to the speaker is connected by a capacitor, and the one side is grounded. A transistor provides charge from the battery into the capacitor, and while it is charging, the speaker has voltage across it, and starts to make a sound. When the transistor is switched off the capacitor discharges via a resistor and the speaker. This generates a reverse voltage across it and completes the other part of the sound waveform. This has now made a complete cycle of the sound, and is repeated thousands of times until the complete croak has been sent out of the speaker. The led thus has alternately positive and negative voltage voltage applied to it, and will light up when it becomes forward biased, the other half of the wave it is reverse biased and does not emit light.
If you look carefully you will find it lights up slightly brighter in one direction than the other. This is due to the transistor being able to deliver more current into the led, while the other way the only source of charge is the capacitor discharging via a resistor and the speaker.