Let $X$ be a smooth hypersurface of degree $d$in $\mathbb{P}^n$ for some $n \ge 3$ and $d>0$. Let $Z_1, Z_2$ be codimension $1$ closed subschemes in $X$ which are locally of complete intersection in $X$. Suppose that the natural morphism $\pi:H^0(\mathcal{O}_X(d)) \to H^0(\mathcal{O}_{Z_1}(d))$ is surjective. Assume that, $Z_1 \subset Z_2$. Then the above morphism factors through $H^0(\mathcal{O}_{Z_2}(d))$. Denote by $\pi_1$ (resp. $\pi_2$) the morphism from $H^0(\mathcal{O}_X(d))$ (resp. $H^0(\mathcal{O}_{Z_2}(d))$) to $H^0(\mathcal{O}_{Z_2}(d))$ (resp. $H^0(\mathcal{O}_{Z_1}(d))$). Is it true that the kernel of $\pi_2$ is contained in the image of $\pi_1$?

No, that is not true. Is there some reason you want that? Maybe if you explain more, then the MO community could help you find a theorem to help. Anyway, take $X$ to be a smooth quadric surface in $\mathbb{P}^3$. Let $e\geq 0$ be an integer, e.g., $e=d=2$. Take $Z_1$ to be the union of $e+1$ disjoint lines contained in $X$. Take $Z_2$ to be the union of $m\geq e+2$ disjoint lines contained in $X$ and containing $Z_1$. Then the following restriction map is an isomorphism, $$ \pi_e:H^0(X,\mathcal{O}_X(e)) \to H^0(Z_1,\mathcal{O}_{Z_1}(e)). $$

On the other hand, the map $\pi_1$ is not surjective, and the kernel $\pi_2$ is not injective. Yet, since $\pi_e$ is injective, and since $\pi_2\circ \pi_1$ equals $\pi_e$, no element in the image of $\pi_1$ can be in the kernel of $\pi_2$.