The diode prevents the voltage from the input to the output from differing too much (You shouldn't put 5V across the output while have a floating or 0V input on the linear regulator). A cap in series would allow for an AC connection but block DC and therefore not be useful, and it would just be a wire in parallel. The Cap is still a good idea, but the diode is just a simple bypass diode. They are cheap and easy to find.