For the question at hand, I think it is important to understand what is meant by $Y \subset Z$ is a quasi-projective variety. The issue is when that inclusion map is not a morphism. For example, $Y$ could be some set whose quasi-projective structure is given by a bijection to some quasi-projective variety sitting nicely in some projective space, but as a subset of $Z$ is quite ugly. Think of a scattered subset of $Z$ that has the same cardinality as the field of complex numbers. (You'd need a more complicated example to take care of the other hypotheses, but this is a start.)
So I am going to assume that the inclusion $Y \subset Z$ is a morphism. (If $Y$ is locally closed (open in its closure) in $Z$, everything with respect to the Zariski topology on $Z$, then this is the case.)
I am also going to assume that the topological "proof left as an exercise to the reader" of user45150 holds, meaning that the hypotheses imply that $f: X \to Y$ is continuous. This is the case when $Y$ is a topological subspace of $Z$.
If $g: Z \to k$ is a regular function, then $g|_Y$ is regular on $Y$, by the assumption that the inclusion is a morphism. Precomposing $g|_Y$ with $f$ gives the same function on $X$ as precomposing $g$, so we get a regular function on $X$ this way.
By definition, one has to show that given an open set $V \subset Y$ and a regular function $\varphi: V \to k$ then $\varphi \circ f: f^{-1}(V) \to k$ is a regular function. You have considered the case $V = Y$, but I don't understand why an arbitrary regular function on $Y$ can be extended to a regular function on $Z$.
I've shown it in the case $Z$ is an affine variety and $Y \subset Z$ is closed, how can I show it in general?
I see that I made a small mess of things.
How about we make the assumption that $Y$ is locally closed in $Z$ with respect to the induced Zariski topology.
Then since you say you know how to do the case where $Y$ is open, it is enough to consider the case where $Y$ is closed (by looking at its closure in $Z$$\ldots$ recall that $Y$ is open in its closure by our assumption of locally closed in $Z$).
Let $V$ be open in $Y$. There exists $U$ open in $Z$ with $U\cap Y=V$. This is by the definition of the induced topology. Note that $V$ is closed in $U$ since $Y$ is closed in $Z$.
By working over $U$ instead of over $Z$, we may assume $U=Z$ and $V=Y$.
Except in the affine case, it is not generally true that regular functions on $Y$ extend to functions on $Z$. However, we can reduce to the affine case, as follows. Let $g$ be a regular function on $Y$. Cover $Z$ by affine opens $U_i$ and let $V_i=U_i\cap Y$. These are still affine since they are closed in the affine $U_i$. They are an open cover of $Y$.
Let $g_i$ be the restriction of $g$ to $V_i$. Extend it to a regular function $G_i$ on $U_i$. We make no claim that we can glue $G_i$ to a regular function on $Z$. However we can pull back $G_i$ to $f^{-1}(U_i)$. Using that $f:f^{-1}(U_i)\to U_i$ factors through the closed subset $V_i$, we see that $g_i\circ f$ agree with $G_i\circ f$ so the former are also regular functions. They glue to a regular function on $X$ since this is a topological question we have at hand and we said that that should be fine and focus on the algebra aspect.