I'm a little confused at which hypotheses are being placed on the spaces involved, but if $X, Y$ and $Z$ are path-connected metric spaces, and we are given functions $h\colon X \to Y$ and $g\colon Y \to Z$ such that $h$ is continuous and surjective, and the composition $g\circ h$ is continuous, then it does not follow that $g$ is continuous:
Example:
Take $X=[0,1)$ and let $h\colon X\to S^1 = \{z \in \mathbb C: |z|=1\}$ be given by $h(t) = \exp(2\pi i t)$. Then $X$ and $S^1$ are Hausdorff and path-connected and $h$ is a continuous surjection. But if we let $g\colon S^1 \to X$ where $g(z) = t\in[0,1)$ and $h(t)=\exp(2\pi i t)=z$, i.e. $g$ is the set-theoretic inverse of $h$, then we have $g\circ h(t)=t$ for all $t \in X$ and hence $g\circ h$ is continuous, but clearly $g$ fails to be continuous at $z=1 \in S^1$.
Update:
The above example generalises to give a necessary and sufficient condition for when a map $h\colon X\to Y$ has the property that for any $g\colon Y \to Z$, $g$ is continuous if and only if $g\circ h$ is continuous precisely when $h$ is a quotient map.
Definition: If $\sim$ is an equivalence relation on a topological space $X$, then we let $X/\sim$ be the set of equivalence classes of $\sim$ and $q \colon X \to X/\sim$ the quotient map sending $x\in X$ to its equivalence class $[x]$. The set of equivalence classes $X/\sim$ has a natural topology, namely we say $U\subseteq X/\sim$ is open precisely when $q^{-1}(U)$ is open. This is the finest topology on $X/\sim$ for which the map $q$ is continuous. If $f\colon X \to Y$ is any function which satisfies $f(x)=f(x')$ whenever $x\sim x'$, then $f$ induces a unique function $\tilde{f}\colon X/\sim \to Y$ satisfying $\tilde{f}\circ q = f$, and $f$ is continuous if and only if $\tilde{f}$ is continuous.
Given any continuous function $f\colon A \to B$ of topological spaces there is an associated equivalence relation $\sim$ on $A$ given by $a_1 \sim a_2$ if $f(a_1)=f(a_2)$. Clearly if $\tilde{A}= A/\sim$ then $f$ factors through $q\colon A \to \tilde{A}$, say $f = \tilde{f}\circ q$. We say that $f$ is a quotient map if $\tilde{f}\colon \tilde{A} \to B$ is a homeomorphism.
Proposition: If $h\colon X \to Y$ is a continuous map then, for any $g\colon Y \to Z$ we have $g\circ h$ continuous if and only if $g$ is continuous precisely when the map $h$ is a quotient map.
Proof: We must show that
$$
g\circ h \text{ is continuous} \implies g \hspace{1mm} \text{is continuous}
$$
holds if and only if $h$ is a quotient map. Let $q\colon X \to \tilde{X}=X/\sim$ be the quotient map where $\sim$ is the equivalence relation $x\sim x'$ if $h(x)=h(x')$. Now any function $f \colon X \to Z$ which satisfies $f(x)=f(x')$ whenever $x\sim x'$ induces a unique function $\tilde{f}\colon \tilde{X} \to Z$ satisfying $f= \tilde{f}\circ q$, and $f$ is continuous if and only if $\tilde{f}$ is. Thus in particular $h=\tilde{h}\circ q$ where $\tilde{h}\colon \tilde{X} \to Y$ is a continuous bijection, and if $g\colon Y \to Z$ is a function, $g\circ h = g\circ \tilde{h}\circ q$ hence $\widetilde{g\circ h} = g\circ \tilde{h}$, and so $g\circ h$ is continuous if and only if $g\circ \tilde{h}$ is.
But now if $h$ is a quotient map, then by definition $\tilde{h}$ is a homoemorphism, i.e. $\tilde{h}^{-1}$ is continuous. But then if $g\circ \tilde{h}$ is continuous, $g = (g\circ \tilde{h})\circ \tilde{h}^{-1}$ is continuous, so the condition that $h$ is a quotient map is certainly sufficient. Conversely if $h$ is not a quotient map, then $g=\tilde{h}^{-1}\colon Y \to \tilde{X}$ is not continuous, while $h \circ \tilde{h}^{-1} = q$ is continuous, so that the continuity of $h\circ g$ does not imply the continuity of $g$ for all $g\colon Y \to Z$.
Lemma Let $h\colon X \to Y$ be a continuous surjection onto a Hausdorff space $Y$. If there exist compact subsets $\{C_i:i \in I\}$ of $X$ such that $\{\mathrm{int}(h(C_i)): i \in I\}$ form a covering of $Y$ by open sets, then $h$ is a quotient map.
Proof: We must show that, given such a collection $\{C_i: i \in I\}$ of compact subsets of $X$, if $F \subseteq Y$ and $h^{-1}(F)$ is closed, then $F$ is closed in $Y$. To see this, note that if $h^{-1}(F)$ is closed in $X$ then for each $i \in I$ the intersection $C_i \cap h^{-1}(F)$ is closed in $C_i$, and hence is compact. Thus $h(C_i\cap h^{-1}(F)))=h(C_i) \cap F$ is compact and therefore closed (as $Y$ is Hausdorff) in $Y$. But then
$$
F\cap \mathrm{int}(h(C_i)) = h(C_i\cap h^{-1}(F))\cap \mathrm{int}(h(C_i))
$$
is closed in $\mathrm{int}(h(C_i))$. Since $\bigcup_{i\in I} \mathrm{int}(h(C_i))=Y$, it follows that $F$ is closed in $Y$ as required.
(Check this!)
Remarks:
In particular, if $X$ is compact, then any continuous surjection $h\colon X \to Y$ to a Hausdorff space $Y$ is always a quotient map.
The conditions that $X$ is path-connected and $Y=\mathbb R$ give a less trivial setting where the hypothesis of the previous Lemma holds: If $y_0 \in \mathbb R$, we may find $z_0,z_1 \in X$ with $h(z_0)= y_0-1$, and $h(z_1) = y_0+1$. Then since $X$ is path-connected, there is a path $\gamma\colon [0,1]\to X$ with $\gamma(0)=z_0$ and $\gamma(1)=z_1$. The composition $\phi=h \circ \gamma \colon [0,1]\to \mathbb R$ is continuous, and hence the Intermediate Value Theorem ensures that $(y_0-1,y_0+1)\subseteq \mathrm{int}(h(\gamma([0,1]))$, and $\gamma([0,1])=C_{y_0}$ is a compact subset of $X$, so that $\{C_{y_0}: y_0 \in Y\}$ is a collection of compact subsets of $X$ satisfying the hypothesis of the Lemma as required.
The Proposition shows that the connectedness of $X$ is not really related to the question of whether $h\colon X \to Y$ can determine whether or not a function $g\colon Y \to Z$ is continuous: Given a quotient map $h\colon X \to Y$ with $X$ connected, if $\mathcal U = \{U_i: i \in I\}$ is an open cover of $X$, then setting $X_{\mathcal U} = \bigsqcup U_i\times I \subseteq X\times I$ (where we give $I$ the discrete topology) and $\pi\colon X_{\mathcal U} \to X$ the restriction of the first projection $X\times I \to X$ to $X_{\mathcal U}$ it is easy to see that $\pi$ is a quotient map and so $h\circ \pi$ is a quotient map, but $X_{\mathcal U}$ is only connected if $\mathcal U = \{X\}$, thus the failure of $X$ to be connected in no way precludes a map $h\colon X \to Y$ from determining the continuity of maps from $Y$.
The example given by M.W. of a continuous map $h\colon X \to Y$ from a connected $X$ to $Y=\mathbb R$ which fails to determine the continuity of maps $g\colon Y \to Z$ is not a quotient map, because, for example, if $F= \{\frac{1}{n\pi}: n \in \mathbb N\}$ then $F$ is clearly not closed in $Y=\mathbb R$, but $h^{-1}(F)= \{(0,\frac{1}{n\pi}): n \in \mathbb N\}$ is closed in $X$.