The clue is that your Lagrangian is independent of $x$. For any Lagrangian function $L\equiv L(\,y(x),y'(x)\,)$:
$$\frac{dL}{dx} \,=\, \frac{\partial L}{\partial y}\,y' + \frac{\partial L}{\partial y'} y'' \quad\Longrightarrow\quad \frac{\partial L}{\partial y}\,y' \,=\, \frac{dL}{dx} - \frac{\partial L}{\partial y'} y''. \qquad\qquad(*)$$
From the Euler-Lagrange equations:
$$\begin{aligned}
\frac{\partial L}{\partial y} - \frac{d}{dx}\left(\frac{\partial L}{\partial y'}\right) \;=\; 0\quad&\Longrightarrow \quad y'\frac{\partial L}{\partial y} - y'\frac{d}{dx}\left(\frac{\partial L}{\partial y'}\right) \;=\; 0 \\[0.2cm]
\quad&\Longrightarrow\quad \frac{dL}{dx} - \frac{\partial L}{\partial y'} y'' - y'\frac{d}{dx}\left(\frac{\partial L}{\partial y'}\right) \;=\; 0 \\[0.2cm]
\quad&\Longrightarrow\quad \frac{dL}{dx} - \frac{d}{dx}\left[y'\frac{\partial L}{\partial y'}\right] \;=\; 0\\[0.2cm]
\quad &\Longrightarrow\quad \frac{d}{dx}\left[ L - y'\frac{\partial L}{\partial y'}\right] \;=\; 0
\end{aligned}$$
where on the second line we substituted in $(*)$. Integrating this, as @user121049 already mentioned, gives you
$$L - y'\frac{\partial L}{\partial y'} \;=\; a$$
for some constant $a$. This is the Beltrami identity; you should be able to use this derivation to help with your problem.
You can expand the textbook solution to get
$$\begin{equation}\begin{aligned}
y & = c_1\sin(4x - c_2) \\
& = c_1(\sin(4x)\cos(c_2) - \cos(4x)\sin(c2)) \\
& = (c_1\cos(c_2))\sin(4x) + (-c_1\sin(c2))\cos(4x)
\end{aligned}\end{equation}\tag{1}\label{eq1A}$$
Note you can choose $c_1$ and $c_2$ values to allow any set of $2$ coefficients for the $\sin(4x)$ and $\cos(4x)$ terms, so this is basically equivalent to your solution.
To see why you have the full range of possible values, the second coefficient divided by the first gives
$$\frac{-c_1\sin(c2)}{c_1\cos(c2)} = -\tan(c_2) \tag{2}\label{eq2A}$$
Since the range of $\tan()$ is all real numbers, this means you can use the corresponding ratio of your two coefficients (call them $c_2'$ and $c_1'$ to help avoid confusion) to get
$$\frac{c_2'}{c_1'} = -\tan(c_2) \tag{3}\label{eq3A}$$
This determines a value of $c_2$ in the range of $0$ to $2\pi$, and with this, if $\cos(c_2) \neq 0$, you can then get $c_1$ from
$$c_1 = \frac{c_2'}{\cos(c_2)} \tag{4}\label{eq4A}$$
else, you can get it instead from
$$c_1 = \frac{-c_1'}{\sin(c_2)} \tag{5}\label{eq5A}$$
I'm leaving out certain details such as with $\cos(c_2) = 0$, i.e., the $\cos(4x)$ term having a coefficient of $0$, but these don't affect the generality of the textbook answer compared to yours.
For a more graphical/visual way to see this, consider the equation of a circle of radius $|c_1|$ centered at the origin is
$$x^2 + y^2 = c_1^2 \tag{6}\label{eq6A}$$
You have that $(c_1\cos(c_2), -c_1\sin(c_2))$, as $c_2$ goes from $0$ to $2\pi$, are the set of all of the points on this circle. As $|c_1|$ goes from $0$ to $\infty$, the set of points on the circle sweeps the entire plane, i.e., all points.
Best Answer
The trick is to rewrite the functional as $$ J[f]~=~\int_1^2 \! \mathrm{d}x~(y^{\prime}+y)^2~\geq~0. \tag{A}$$
Clearly a solution to $$y^{\prime}+y~=~0 \tag{B}$$
would minimize the functional (A). If we combine the first-order ODE (B) with the boundary condition
$$ y(1)~=~1\tag{C} $$
we get the sought-for solution
$$ y(x)~=~e^{1-x}. \tag{D} $$