Mechanical energy conservation works but you applied it incorrectly. You stated mechanical energy conservation as
laser said:
Energy before compression = Energy at compression.
which can be misleading. A preferred way to write it is in terms of energy
changes, $$\Delta K+\Delta U$$ between a starting point A and an ending point B. Here, you want to find the distance by which the spring is compressed when the mass is at equilibrium. Call that distance ##x=x_{eq}##.
Suppose you release the block from rest at point A which is the relaxed position of the spring. The block will descend acquiring kinetic energy at the expense of potential energy until it reaches ##x_{eq}.## However, it will not stop there because at the equilibrium point the acceleration is zero but not the speed. At the equilibrium point the mass has acquired maximum kinetic energy ##K_{max}##. It is maximum because past that point, the acceleration changes direction and the speed and kinetic energy decrease.
Now all forces are conservative. Therefore, if the mass gains kinetic energy ##K_{max}## after descending distance ##x_{eq}## when the acceleration is in the same direction, it will need to descend an
additional distance ##x_{eq}## when the acceleration is reversed in order to
lose ##K_{max}## and reach maximum compression at ##x=x_{max}.## Thus, $$x_{max}=2x_{eq}.$$ Now we write the energy conservation equation from point of release A to point of maximum compression B, $$\begin{align} & \Delta K+\Delta U_{\text{spring}}+\Delta U_{\text{grav.}}=0 \nonumber \\
& (0-0)+\left(\frac{1}{2}kx_{max}^2-0\right)+(0-mgx_{max}\sin\theta)=0 \nonumber \\
&\frac{1}{2}kx_{max}^2=mgx_{max}\sin\theta \implies x_{max}=\frac{2mg\sin\theta}{k}. \nonumber \\
\end{align}.$$ We have seen that ##x_{max}=2x_{eq}.## Therefore, $$x_{eq}=\frac{mg\sin\theta}{k}$$ which is what one gets using the force equilibrium argument.