How can we guess one solution of the equation $y''+\frac{2}{x}y'+y=0$? I want to solve the equation $$\frac{1}{x^2} \, \frac{d}{dx}\left(x^2\frac{dy}{dx}\right)=-y.$$ I converted it to this equation $y''+\frac{2}{x}y'+y=0$. How can we guess one solution of the equation $y''+\frac{2}{x}y'+y=0$? Is there any way to solve it generally?

One thing to try for non-constant coefficients second order linear ode's is the Liouville transformation. This involves no guessing and is one of the methods to try for such ode's if other methods fail.
Solve
\begin{align*} 
y''+\frac{2 y'}{x}+y&=0\\ \tag{1} 
A y''+ B y' + C y&=0
\end{align*}
Hence $A=1,B=\frac{1}{2},C=1$. Applying the Liouville transformation on the dependent variable gives
\begin{align*}
z(x) &= y e^{\int \frac{B}{2 A} \,dx}  \tag{2} 
\end{align*}
Then (1) becomes
\begin{align*}
z''(x) = r z(x)\tag{3}
\end{align*}
Where $r$ is given by
\begin{align*}
r &= \frac{2 A B' - 2 B A' + B^2 - 4 A C}{4 A^2} \\
  &= -1
\end{align*}
Hence (3) becomes
\begin{align*}
z''(x) + z(x) = 0
\end{align*}
This is constant coefficient ode now. Its solution is easily found to be $z=\cos x$. Applying (2) again in reverse to find the first basis solution for the $y$ ode gives
\begin{align*} 
y_1 &= z e^{-\int \frac{B}{2 A} \,dx}\\
  &= z e^{ -\int \frac{1}{2} \frac{\frac{2}{x}}{1} \,dx}\\
  &= z e^{-\ln \left(x \right)}\\
  &= z \left(\frac{1}{x}\right)\\
  &= \frac{\cos \left(x \right)}{x}
\end{align*}
The second basis solution $y_2$ to the original ode is found using reduction of order
\begin{align*} 
y_2 &= y_1 \int \frac{  e^{\int -\frac{B}{A} \,dx}}{y_1^2} \,dx \\
y_2 &= y_1 \int \frac{  e^{\int -\frac{\frac{2}{x}}{1} \,dx}}{\left(y_1\right)^2} \,dx\\
    & = y_1 \int \frac{ e^{-2 \ln \left(x \right)}}{\left(y_1\right)^2} \,dx\\
    &= y_1 \left(\tan \left(x \right)\right)
\end{align*}
Therefore the solution is
\begin{align*} 
y &= c_1 y_1 + c_2 y_2\\
  &= c_1 \frac{\cos \left(x \right)}{x} + c_2 \frac{\cos \left(x \right)}{x} \tan \left(x \right)\\
  &= c_1 \frac{\cos \left(x \right)}{x} + c_2 \frac{\sin \left(x \right)}{x} \\
\end{align*}

Another thing to also always try with non-constant coefficient is solving as Bessel ODE using Bowman method. This works if one is able to solve for the unknown using linear algebra solver
Start by writing the ode as
\begin{align*}
x^{2} y^{\prime \prime}\left(x \right)+2 x y^{\prime}\left(x \right)+x^{2} y \left(x \right) = 0\tag{1} 
\end{align*}
But Bessel ode has the form
\begin{align*}
x^{2} y^{\prime \prime}\left(x \right)+x y^{\prime}\left(x \right)+\left(-n^{2}+x^{2}\right) y \left(x \right) = 0\tag{2} 
\end{align*}
The generalized form of Bessel ode is given by Bowman (1958) is the following
\begin{align*}
x^{2} y^{\prime \prime}\left(x \right)+\left(1-2 \alpha \right) x y^{\prime}\left(x \right)+\left(\beta^{2} \gamma^{2} x^{2 \gamma}-n^{2} \gamma^{2}+\alpha^{2}\right) y \left(x \right) = 0\tag{3}
\end{align*}
With is standard solution being
\begin{align*}
y \left(x \right)&=x^{\alpha} \left(c_{1} \operatorname{BesselJ} \left(n , \beta  \,x^{\gamma}\right)+c_{2} \operatorname{BesselY} \left(n , \beta  \,x^{\gamma}\right)\right)\tag{4}
\end{align*}
Comparing (3) to (1) and solving for $\alpha,\beta,n,\gamma$ gives (little algebra)
\begin{align*}
     \alpha &= -{\frac{1}{2}}\\ 
     \beta &= 1\\ 
n &= {\frac{1}{2}}\\ 
\gamma&= 1
\end{align*}
Substituting all the above into (4) gives
\begin{align*}
\frac{1}{\sqrt x}\left(c_1 \operatorname{BesselJ}\left(\frac{1}{2},x\right)
+ \operatorname{BesselY}\left(\frac{1}{2},x\right)\right) \tag{5}
\end{align*}
But
\begin{align*}
\operatorname{BesselJ}\left(\frac{1}{2},x\right)&=\frac{\sqrt{2}\, \sin \left(x \right)}{\sqrt{\pi}\, \sqrt{x}}\\
\operatorname{BesselY}\left(\frac{1}{2},x\right) &= -\frac{\sqrt{2}\, \cos \left(x \right)}{\sqrt{\pi}\, \sqrt{x}}
\end{align*}
Hence (5) becomes
\begin{align*}
y \left(x \right) = \frac{c_{1} \sqrt{2}\, \sin \left(x \right)}{x \sqrt{\pi}}-\frac{c_{2} \sqrt{2}\, \cos \left(x \right)}{x \sqrt{\pi}}
\end{align*}
The constants can be rewritten and the above becomes
\begin{align*}
y \left(x \right) &= C_{1} \frac{\sin \left(x \right)}{x }+ C_{2} \frac{\cos \left(x \right)}{x}
\end{align*}
