Why is the voltage dropping when using pwm output pin of a microcontroller?
When you connect a diode or capacitor between an output and ground, you are effectively either pulling that pin to one diode drop from ground or temporarily short-circuiting it to ground through the capacitor.

Either way, when the output then switches high, this drags the IC supply voltage down to this low value through the pull-up transistor in the output driver, subsequently causing a brownout condition if the supply cannot supply enough current to compensate.

Additionally, a diode reverse-biased between the 5V supply and ground will not conduct enough current to cause a brownout, while a forward-biased diode would conduct enough current to possibly burn itself out after a few seconds, depending on what the supply can handle in terms of current.

As for the capacitor across the supply, it will only be a short circuit until it charges up, then it will effectively be an open circuit. This differs from connecting it to a PWM output in that the PWM output switches between high and low. When high, the capacitor behaves exactly as it does when you initially put it across the supply, acting as a short circuit. However, the PWM output doesn't stay high. When it drops low, it discharges the capacitor, resetting it to look like a short circuit again when the output goes high.