A convolution cannot centre its kernel on a pixel at the very edge, since part of it hangs off.
So without help the output comes back slightly smaller than the input.
A 3 by 3 kernel on a 32 by 32 image gives 30 by 30.
Do that twenty times and there is nothing left to convolve.
Padding adds a border of extra pixels around the image, usually zeros.
Same padding sizes that border so the output matches the input exactly.
Valid padding adds nothing and accepts the shrinkage, which is the other common setting.
Same padding is the usual default, since it keeps the architecture easy to reason about.
It also fixes a subtler problem at the edges.
Without padding, a corner pixel is covered by far fewer kernel positions than a central one.
The model therefore sees the edges of every image less often than the middle.
That matters when the subject is not neatly centred.
Zeros are the standard filler, and reflecting or repeating the edge pixels is also used.
Zero padding does introduce a thin artificial border the network learns to recognise.
It is a small distortion and universally accepted as worth the convenience.