First understand how an ESC works.. It controls voltage by
switching off and on the supply very fast. The more time that is 'on' the higher the voltage on the output, the more time it's 'off' the lower the voltage. This 'switching' on and off means that the flow of electricity coming in from the battery also pulses on and off.
Now you need to understand another property of electricity flowing through wires, a phenomenon called
'inductance'. In reality inductance is related to the magnetic field that the flow of electricity generates, but to make it easier to understand think of electricity to be like water flowing through a pipe. If you had water flowing through a pipe very fast and you instantly closed a valve you would get a surge of pressure due to the momentum of the water, this is called water hammer and might make your pipes 'bang' at home. Electricity is the same, if it's flowing fast along the wires into the ESC, then the ESC instantly switches the flow off you get a surge, not in pressure but in voltage.
These surges in Voltage caused by the switching would cause damage to the components in the ESC, so the ESC is protected by having large capacitors on the input from the battery. The capacitors work a bit like a damper to absorb the on and off pulses and allow the current to flow smoothly from the battery, thus avoid the voltage surges that would otherwise damage the ESC.
This also explains why length of wire between battery and ESC is critical. If you make those wires longer there is more inductance in the wire and more surges for the capacitors to absorb, which may be too much for them and the surge gets through to the ESC components. Some manufacturers sell extra capacitor packs that you add to the wires if you want to extend them.
The capacitors only store a minute amount of charge, not nearly enough to actually supply any 'extra' power to the ESC for more than a few milliseconds, they are there purely to protect the ESC from voltage spikes due to inductance. Apparently on a 20V supply, without capacitors, you could get voltage spikes over 100V.