I thought input capacitors are used only for providing a constant DC supply during power interruptions to the downstream circuit. In the first image, it is writter as "Add cap for filtering high peak currents". I dont understand how a capacitor can filter high peak currents. Please explain with an analogy.
Capacitors can't provide DC current when the power source is off but most can provide a high-value current for a short amount of time. Decoupling capacitors are used as an energy tank that is emptied quickly when there is a sudden change of current in the circuit (for instance Q1 turning-on) so that your circuit does not need to source these extra short pulses of current directly from the power source.
If your circuit had to source this extra current from the power source and given the resistance of this path is much higher than the resistance of the path to the local decoupling capacitor, you'll end up with a higher voltage ripple on the input of Q1 (V = R x I, if R is higher then V is higher).
You'll also create longer current paths and loops which in turn can generate undesirably high magnetic fields which can couple in the rest of your circuit (eg. becoming noise source for other components).
To ensure that Cin is effectively used when the high peak current pulses happen, it needs to have a low-equivalent resistance (ESR) as, when those pulses happen, you want Cin to be the lowest path of resistance. If not, the switching circuit may source it from elsewhere. MLCC capacitors have very low ESR, a combination of these in the proximity of Q1's drain will act as "low resistance energy tanks" which are very effective in "filtering" peak currents.
Why do we need short traces at switching nodes and why do we need to keep the loop area small?
I mentioned above that higher current loops create higher magnetic fields, it is true here too. So in keeping the switch node trace short, you'll effectively create tiny current loops and contain the radiated energy locally. If you get loose on that rule, the radiation can travel further and affect the rest of your circuit and/or other circuits near-by. To avoid this case scenario is one of the reasons why most electronics are tested for electromagnetic compliance before they can be sold.