I am slightly confused about the definition of smooth functions on a smooth manifold given in An Introduction to Manifolds by Loring Tu (Second Edition, page no. 59). The definition is given below.
I am confused because I don't see how $f\circ \phi^{-1}$ is, in general, defined. Let $\phi: U \to X$, where $X$ is an open subset of $\mathbb{R}^n$. Here, $\phi^{-1}: X \to U$. Then $f\circ \phi^{-1}$ is defined if the codomain of $\phi^{-1}$ is equal to the domain of $f$, which is not the case. Because the codomain of $\phi^{-1}$ is $U$ and the domain of $f$ is $M \supset U$. To my understanding, what we can define is $\left.f\right|_{U}\circ \phi^{-1}$, where $\left.f\right|_{U}$ is the restriction of $f$ to $U$. I am missing something here?

You are right, although your heart will be lighter if you will accept such notation when nothing is unclear, since the restriction symbol is bulky and hard to read.