Assume $g\circ f$ is not constant and $f$ is surjective and proper.As holomorphicity is a local condition we can assume $X$ and $Y$ are open subsets of $\Bbb C$.
Since the zeroes of a holomorphic function are isolated, the points $x$ where $(g\circ f) '(x)=0$ are isolated in $X$. Call this set of isolated points $S$.
Away from these points $g\circ f$ is a local biholomorphism and in particular $g$ is holomorphic on $Y-f(S)$ with $g'(z)=\frac1{f'(g(z))}$ in some local holomorphic coordinates. I claim $g|_{Y-f(S)}$ is bounded locally around each point of $f(S)$ and can hence be extended over each point of $f(S)$ holomorphically in a unique way.
If $g$ is not bounded around a point in $y \in f(S)$, then it either has a pole or an essential singularity at $y$ by the classification of isolated singularities.
If $g$ has a pole at $y$, locally $g(z)=\frac1{(z-y)^k}g_1(z)$ where $g_1(z)$ is holomorphic and injective on a neighborhood of $y$ and $g_1(y)\ne 0$. Now locally around $x$ with $f(x)=y$ we have $g(f(z))= \frac1{(f(z)-y)^k}g_1(f(z))$ which has a pole of order $qk$ at $x$ where $q$ is the order of vanishing of $f(z)-y$. In particular $q\geq 1$ and $g \circ f$ has a pole at $x$, which is a contradiction.
If $g$ has an essential singularity at $y$, then the image of any punctured neighborhood of $y$ under $g$ is dense in $\Bbb C$ by the Casorati–Weierstrass theorem. As $f$ is locally surjective at point $x$ with $f(x)=y$, the image of any neighborhood of $x$ under $g\circ f$ must be dense in $\Bbb C$, but then $g\circ f$ is not continuous, so we have a contradiction and the points $f(S)$ are isolated removable singularities of $g|_{Y-f(S)}$.
To see that $g$ must coincide with this extension, it is enough to show $g$ is continuous. Let $y_n$ be a cauchy sequence with $y_n$ converging to $y=f(x)$ but $g(y_n)$ not converging to $g(y)$. As $f$ is holomorphic, it is locally surjective (near $y$) and for sufficiently large $y_n$, $y_n=f(x_n)$ for some sequence $x_n$. By properness $x_n$ has a convergent subsequence (converging to $x_0$) and by continuity of $g\circ f$, we have $g(y_n)=g(f(x_n)) \to g(f(x_0))=g(y)$. Hence $g$ is continuous.