If you know how to solve higher order linear ODE, then you can just note that the PDE you have contains only derivatives with respect to $x$, so it is essentially a linear homogeneous ODE, with auxiliary equation $m^2 + 1 = 0 \Rightarrow m = \pm i$, for which the solution is $c_1\cos(x) + c_2\sin(x)$. As we actually have a PDE (with the only other independent variable being $y$), $c_1$ and $c_2$ should be functions of $y$ rather than pure constants.
If you want a "from scratch" solution, here goes...
Let $\partial_x = \dfrac{\partial}{\partial x}$. Then the given PDE is $\partial_x^2z + z = 0$, or $(\partial_x^2 + 1)z = 0$. This can be written as $(\partial_x + i)(\partial_x - i)z = 0$ (the validity of this factorization of the operator can be verified by actually carrying out the differentiations and verifying that this becomes the original equation - you will see that it is only a convenient notation). Thus we have to solve
$$(\partial_x + i)(\partial_x - i)z = 0$$
Let $(\partial_x - i)z = w$. Then the equation becomes
$(\partial_x + i)w = 0\Rightarrow\\
\partial_x w = -iw \Rightarrow\\
\dfrac{1}{w} \partial_xw = -i \Rightarrow\\
\partial_x (\log w) = -i \Rightarrow\\
\log w = -ix + C(y) \Rightarrow\\
w = c_1(y) e^{-ix} \qquad (\text{where we have written $e^{C(y)}$ as $c_1(y)$})
$
Now, as $(\partial_x - i)z = w$, we have
$
\partial_x z - iz = c_1(y)e^{-ix} = c_1 e^{-ix} \Rightarrow\\
\dfrac{\partial z}{\partial x} - iz = c_1 e^{-ix}
$
This is a first order linear equation that can be solved using the integrating factor $e^{\int (-i)\, dx} = e^{-ix}$. Therefore:
$z\times \text{IF} = \displaystyle \int \text{RHS}\times \text{IF} \,dx \Rightarrow\\
z e^{-ix} = \displaystyle \int c_1 e^{-2ix} \,dx \Rightarrow\\
z e^{-ix} = c_1 \dfrac{e^{-2ix}}{-2i} + c_2 a = C_1 e^{-2ix} + C_2 \Rightarrow\\
z = C_1 e^{-ix} + C_2 e^{ix} \Rightarrow\\
z = C_1(\cos x - i \sin x) + C_2(\cos x + i \sin x) \Rightarrow\\
z = (C_1 + C_2) \cos x - i(C_1 - C_2) \sin x \Rightarrow\\
z = A \cos x + B \sin x
$
Now as the equation is actually a PDE, $A$ and $B$ are functions of $y$, say $A = f(y)$ and $B = g(y)$. Thus
$$\boxed{z = f(y)\cos x + g(y) \sin x}$$