Munkres is proving the following statement:
"Let $f: \ X \ \rightarrow \ Y$ be continuous. If $f(X) \ \subset \ Z \ \subset \ Y$, we show that the function $g: \ X \ \rightarrow \ Z$ obtained from $f$ is continuous."
He proves it the following way:
"Let $B$ be open in $Z$. Then $B \ = \ U \ \cap \ Z$ for some open set $U$ of $Y$. Because $Z$ contains the entire image set $f(X)$, then $f^{-1}(U) \ = \ g^{-1}(B)$. This then implies that $g$ is continuous.
Now, I understand most of this proof, however, I don't understand the how Munkres arrived at $f^{-1}(U) \ = \ g^{-1}(B)$. We get that $g^{-1}(U \ \cap \ Z) \ = \ g^{-1}(U) \ \cap \ g^{-1}(Z) \ = \ g^{-1}(U) \ \cap \ X \ = \ g^{-1}(U)$, but how can we instantly equate this to $f^{-1}(U)$? If we chose a $U$ that is not in $Z$, how would $f^{-1}(U) \ = \ g^{-1}(U)$?
First, note that $g^{-1}(U)$ isn’t necessarily defined, since the codomain of $g$ is $Z$, and $U$ is an arbitrary open set of $Y$.
To prove this, we see that we can decompose $U$ into pieces: $U = B \cup (Z\setminus U)$, where the preimage (under $f$) of $Z\setminus U$ must be empty. Now with that in hand, we have:
$$f^{-1}(U) = f^{-1}(B\cup (Z\setminus U) = f^{-1}(B) \cup f^{-1}(Z\setminus U) = g^{-1}(B) \cup\emptyset = g^{-1}(B).$$