Here is the question I am trying to prove:
If $M$ is a smooth manifold, let $C^{\infty}(M)$ be the set of smooth functions $M \to \mathbb R.$ The set $ C^{\infty}(M) $ is an $\mathbb R$-algebra under pointwise addition and multiplication of functions. Show that if $f: M \to N$ is a smooth function, then $$f^*: C^{\infty}(N) \to C^{\infty}(M), \textbf{ defined by } \phi \mapsto \phi \circ f$$ satisfies $$(f\circ g)^* = g^* \circ f^*.$$
I am having hard time understanding the domain of $g^* \circ f^*$.
If $f: M \to N$ and $g: N \to M' \subset M,$ then $f^*: C^{\infty}(N) \to C^{\infty}(M)$ and $g^*: C^{\infty}(M') \to C^{\infty}(N)$ and $(f \circ g)^*: C^{\infty}(M') \to C^{\infty}(M)$ but what is the domain and codomain of $g^* \circ f^*,$ I find it is not matching with the domain and codomain of $(f \circ g)^*$ even though they are equal functions. Could anyone help me understand this please?
If you want to compose $g$ first then $f$ you must regard $g$ as a map $g: N \to M$. If you wish to regard $g$ as a map $g: N \to M'$ where $M' \subseteq M$ then you are honestly forming the composite $f \circ (i \circ g)$ where $i: M' \to M$ is the inclusion. You need to choose one of these alternatives: that is why your confusion on domain/codomain exists. Once you get definite about this, there won't be any more confusion on the compositon of $f^*$ with $g^*$ (and possibly $i^*$ if needed).
In the first option above (where $g: N \to M$) we have $$ C^{\infty}(N) \stackrel{f^*}{\longrightarrow} C^{\infty}(M) \stackrel{g^*}{\longrightarrow} C^{\infty}(N) $$ and so the identity $(f\circ g)^* = g^* \circ f^*$ makes sense (and is true). In the second case (where $g: N \to M'$) we would have $$ C^{\infty}(N) \stackrel{f^*}{\longrightarrow}C^{\infty}(M) \stackrel{i^*}{\longrightarrow} C^{\infty}(M') \stackrel{g^*}{\longrightarrow}C^{\infty}(N) $$ and everything still matches up correctly, with $(f\circ i \circ g)^*=g^* \circ i^* \circ f^*$. And, as mentioned, the interpretation of the intermediate $i^*: C^{\infty}(M) \to C^{\infty}(M')$ is straightforward: smooth functions on $M$ may be restricted to smooth functions on the submanifold $M'$ and retain smoothness.