For the protection of the diode use the series resistor to allow the required current to flow in the LED for the required brightness. The capacitor will allow to help the LED to become OFF slowly depending on the capacitance used when the DC power is suddenly removed.
It depends on how the LED is connected. In some crude power supplies, an LED is used as the voltage reference and the capacitor across it may be to reduce the noise it produces. If the LED is fed from rectified AC, the capacitor may be there to prevent annoying flickering. In one instance here, the LED is on long wires and the capacitor is simply to prevent them acting like antennas which could feed signals back into my circuitry.
Capacitor's impedance is inversely proportional to frequency, that means high frequency swings see capacitor as a short circuit , so the high frequency currents follow the path from the capacitor rather than the LED, saving the LED from damaging, and so this is how the capacitor saves the LED from High Frequency currents, basically it bypasses the LED.
Capacitor's impedance is inversely proportional to frequency, that means high frequency swings see capacitor as a short circuit , so the high frequency currents follow the path from the capacitor rather than the LED, saving the LED from damaging, and so this is how the capacitor saves the LED from High Frequency currents, basically it bypasses the LED.
All the answers are based on assumptions of what type of power source is used. So, until we have the exact circuit diagram difficult to say the correct reason.