Proper way to solve this physicist differential equation

Given the DGL: $y''= -k^{2}y$

I tried solving this with the quadratic form attempt: $y_{1,2} = \frac{-k^{2}}{2} \pm \frac{\sqrt{k^{4}-4}}{2}$

A good solution attempt is $A\cos(bx)+B\sin(bx)$, I know that. How does one reach there without knowing this solution attempt?

-

The trigonometric functions $\cos(x)$ and $\sin(x)$ both satisfy $y'' = -y$.
It is straightforward to show that both, $\cos(kx)$ and $\sin(kx)$ satisfy $y'' = -k^2y$ and your result follows by the superposition principle, since the DE is linear.
In general, for a contant-coefficient homogeneous linear differential equation $P(D) y = 0$, where $D = \frac{d}{dx}$ and $P$ is a polynomial of degree $n$ with $n$ distinct roots $r_1, \ldots, r_n$, the general solution is $y(x) = \sum_{j=1}^n c_j e^{r_j x}$ where $c_1, \ldots, c_n$ are arbitrary constants. In your case, assuming $k \ne 0$, $P(t) = t^2 + k^2$ has the two roots $\pm k i$, so the general solution is $y(x) = c_1 e^{ikx} + c_2 e^{-ikx}$. Since $e^{ikx} = \cos(kx) + i \sin(kx)$, an alternate form of the general solution is $y(x) = A \cos(k x) + B \sin(k x)$, where $A = c_1 + c_2$ and $B = i c_1 - i c_2$.