As the title states, say I have a function $f(x,y)$ and I am given $y$ as a function $y(x)$. Say I take the partial derivative of $f$ with respect to $x$: apparently, I am just supposed to let $y$ be a constant as if it were unrelated to $x$, as I can see by googling or from other questions on this site. (For example, this question has an answer which says so, but with no explanation.)
My question then, is why? The way I've learnt partial derivatives is always via a sort of geometric intuition: draw the surface described by $z=f(x,y)$ in $\mathbb{R}^3$, and to take $\partial f/\partial x$ is to draw a plane parallel to the $x$ and $z$ axes and orthogonal to the $y$ axis, and look at the slope of the curve along intersection of the surface of the plot and the plane. It seems then, that we can't treat $y$ as constant in the event that they are non-independant, since doing so would imply that some points on the $xy$-plane as in the previous visualisation would not be achievable. (For example, if $y=x^2$ and $f(x,y)=x+y$, it doesn't make sense to consider the point $(1,2,3)$ since it's not achievable.) I would think then that to take $\partial f/\partial x$ would require finding explicitly a function $g(x)$ so that $g(x)=f(x,y)$, then taking $\partial g/\partial x$, but apparently that is not the case.
Taken to the extreme, say $x=y$ and we have, say, $f(x,y)=x^2+y^2$. According to what's supposed to be the case, $$ \frac{\partial f}{\partial x}(x,y) = 2x. $$ If we however first substitute $x=y$ we will get $4x$. Why is my reasoning wrong? And why is the correct reasoning, well, correct?
(To be clear: I have no problems with taking partial derivatives if the variables are unrelated. I don't think this will be very useful, but for context, I encountered this in trying to apply the Euler-Lagrange equation in an applied math problem. I came into this issue as the equation required me to take the partial derivative of a function $\mathcal{L}(q,q',t)$ with respect to $q'$, where $q'=dq/dt$.)