If $f$ is continuous, this kind of arrangement can't happen. To see this, consider a continuous path going from the the $f=1$ curve to the $f=4$ curve. Let $(x(t), y(t))$ denote a (continuous) paramaterization of such a path with, say $(x(0), y(0))$ a point on the $f=1$ curve and $(x(1), y(1))$ a point on the $f=4$ curve.
Then we get a single variable continuous function by mapping $t$ to $f(x(t),y(t))$. If we plug in $t=0$, we get $f(x(0), y(0)) = 1$ and likewise, if we plug in $t=1$, we get $f(x(1), y(1)) = 4$. By the intermediate value theorem, there is some $t$ we can plug in for which $f(x(t),y(t)) = 3$.
In terms of your picture, what this says is that any continuous curve which starts at the $f=1$ curve and ends at the $f=4$ curve must pass through the $f=3$ curve. If you think about this, you should be able to convince yourself that this forces the curves $f=1$, $f=3$, and $f=4$ to be concentric, as it is in the pictures you typically see.
Edit: Let me try to address it a little differently so that you can see why the connectedness of the $f=3$ curve is irrelevant. The issue is that no one is claiming that a place where $f$ and $g$ are tangent is a max or min of $f$. Rather, the claim is the the only hope of finding a max or min of $f$ is at a point where $f$ and $g$ are tangent (for reasonbly smooth $f$ and $g$), or where $f$ already has a max or min.
Here is the argument (which is essentially what amd wrote in his/her answer) with a bit more hand waving.) Suppose $(x_0,y_0)$ is a point along the curve $g(x,y) = c$ for which $f(x_0,y_0)$ is a maximum. (I'll use notation for the value $d = f(x_0,y_0)$.)
The question is: how are $f$ and $g$ related at $(x_0,y_0)$?
Well, zoom in incredibly close to $(x_0,y_0)$. At this resolution, all you see is a very small part of the curve $g(x,y) = c$ and a very small portion of one connected piece of the curve $f = d$. The point is that while the curve $f=d$ may have infinitely many components, we are zooming in so far as to only see the a part of the one containing $(x_0,y_0)$.
Because we are zoomed in very close, for intuition purposes, we may as well replace $g$ and $f$ by their tangent lines. If these tangent lines are different, then the line $g = c$ passes from one side of the line $f = d$ to the other. If $f$ does not have a local min/max at $(x,y)$, then the values must be higher on one side of the $f$-line and lower on other. Since the line $g = c$ crosses the line $f = d$, by using points on one side or the other of the $f$-line, we can find points on $g=c$ which make $f$ even bigger than $d$. This is a problem: $d$ was supposed to be the maximum value!
So something had to go wrong. We have already identified both problems. First, maybe the tangent line to $f$ was equal to the tangent line to $g$. Then the $g$ line doesn't cross the $f$ line. Second, if $f$ has a local max at $(x,y)$ then points on $g(x,y) =c$ don't increase the size of $f$ as the $g$ line crosses the $f$ line. (Another thing that could go wrong: maybe $f$ just doesn't have a maximum subject to the constraint. This issue actually can't arise if the graph of $g = c$ doesn't go off to infinity in some direction.)