I think the answer to your question is already given in the answers to the couple questions you mention, it just doesn't appear integrated into a single answer, so I think it's convenient to write it here.
It is convenient to say that this problem corresponds to Exercise 1.3 (with a star) of Guillemin and Pollack's book, Differential Topology.
Let us therefore remember the definitions that Guillemin and Pollack offer in that book:
First we write the definition of smoothness in the classical sense, i.e., on open sets of $ \mathbb R ^ n $ (Guillemin and Pollack do not use the term "classical" but it suits us to handle it like this for our explanation):
A maping $f$ of an open set $U\subset\mathbb R^n$ into $\mathbb R^m$
is called smooth if it has continuous partial derivatives of all
orders. (Page 1)
Then, we write the "extended" version (on arbitrary sets):
A map $f:X\to\mathbb R^m$ defined on an arbitrary subset $X$ in
$\mathbb R^n$ is called smooth if it may be locally extended to a
smooth map on open sets; that is, if around each point $x\in X$ there
is an open set $U\subset\mathbb R^n$ and a smooth map [in the
classical sense] $F:U\to\mathbb R^m$ such that $F$ equals $f$ on
$U\cap X$. (Pages 1 and 2)
Let then $ X \subset \mathbb R ^ n $, $ Y \subset \mathbb R ^ m $, $ Z \subset R ^ k $ be arbitrary subsets and let $ f: X \to Y $ y $ g: Y \to Z $ smooth maps (extended sense). We want to show that the composition $ h = g \circ f: X \to Z $ is smooth (extended sense).
In the case of $ X $, $ Y $ and $ Z $ open this is a typical calculus result that is explained here.
In the general case we proceed as follows:
Let $ x \in X $. Since $ f $ is smooth (extended sense), there exists an open $ U \subset \mathbb R ^ m $ and a function $ F: U \to \ R ^ n $ smooth (classical sense) such that
$$
x\in U \qquad \text y \qquad F|_{U\cap X}=f.
$$
Let $ y = f (x) \in Y $. Since $ g $ is smooth (extended sense), there is an open $ V \subset \mathbb R ^ n $ and a function $ G: V \to \mathbb R ^ k $ smooth (classical sense) such that
$$
y=f(x)\in V \qquad \text y \qquad G|_{V\cap Y}=g.
$$
Of course we would like to take the composition $ G \circ F $ as the smooth function (classical sense) that smoothly extends the function $ h $, but it is not possible to do this for the reasons explained here.
So if we set
$$
\widehat F=F|_{U\cap F^{-1}(V)}:U\cap F^{-1}(V)\to \mathbb R^n
$$
then $ \widehat F $ is smooth (classical sense) and since $ U \cap X \cap F ^ {- 1} (V) \subset U \cap X $, it follows that
$$
\widehat F|_{U\cap X}=F|_{U\cap X}=f.
$$
We set
$$
H=G\circ\widehat F:U\cap F^{-1}(V)\to\mathbb R^k.
$$
Then $ H $ is smooth (classical sense) and if $ \xi \in U \cap X $, $f(\xi)\in V\cap Y$, and therefore
$$
H(\xi)=G(\widehat F(\xi))=G(f(\xi))=g(f(\xi))=h(\xi).
$$
That is $H|_{U\cap X}=h$ and $h$ is smooth (extended sense).
Many other solutions to starred exercises from Guillemin and Pollack's book can be found here.