The Sobel Filter is a $ 3 \times 3 $ matrix (it is separable, but let's ignore that).
The anchor pixel is the middle one hence to evaluate the operator on pixels on the upper row the operator needs data above them.
Same goes for pixels on the last row, left-most column or right-most column.
This is usually solved by padding the image (I actually use "Replication" instead of Zero Padding).
Another option is to set the output to be smaller image by not evaluating the extreme rows or columns.
Zero padding IS not required, per se. However, rooting on the centered $3\times 3$ square kernel, pixels on the borders of the image lack outer neighbors, if one wants to estimate their discrete derivative/smoothing. So you have to, either:
- use a shorter derivative estimator on image borders (which does not make assumptions regarding side effects), like Roberts cross edge detectors, or
- extend the image properly; zero-padding (for centering, one more row or column on the right and left, and bottom or bottom, suffices) is the simplest version, but symmetric/anti-symmetric, periodic or mirror extensions can be more appropriate, or
- use non-linear operators, that could be more robust, or
- discard border values, which you cannot compute in any sound manner without assumptions.