Let's start with the single variable case and then it'll be clear how it applies to multiple variables. The mean value theorem states that if we have a function $f(x)$ that is continuous on an interval $[a,b]$ and differentiable on $(a,b)$, then there is some $c\in (a,b)$ where $$f'(c) = \frac{f(b)-f(a)}{b-a},$$ which essentially means that the "average slope" of a function over an interval must be equal to the instantaneous slope at one point in that interval.
Let's assume that $f\colon [a,b] \to \mathbb{R}$ is a continuous function on $[a,b]$ and differentiable on $(a,b)$ with $f'(x) = 0$ for all $x\in (a,b)$. Striving for contradiction, assume $f(x_1) \ne f(x_2)$, for some $x_1,x_2 \in [a,b]$, i.e. that $f$ is nonconstant. Indeed, then we have $$\frac{f(x_2)-f(x_1)}{x_2-x_1}\ne 0$$ which means that for some $c \in (x_0, x_1)\ne \varnothing$ we have $f'(c) \ne 0$, which contradicts our assumption that $f'(x)$ was identically zero on $(a,b)$.
Generalizing to the multivariable setting, let $f\colon \mathbb{R}^2 \to \mathbb{R}$ be differentiable (and thus continuous on $\mathbb{R}^2$) such that $\frac{\partial f}{\partial y} = 0$. Then, we'll assume that $f$ depends on $y$, i.e. that $f(x, y_1)\ne f(x,y_2)$ for some $y_1\ne y_2$ and strive for contradiction. If we define $g\colon \mathbb{R}\to \mathbb{R},\ g(t) := f(x,t)$, then $g'(t) = 0$ for all $t$ by our assumption. However, $g(y_1) \ne g(y_2)$, so we can apply the above result to this now single variable function and obtain a contradiction.