I tried to explain this in my original response in post #2 and later in post #11.If the change of potential energy is mgΔx , why the spring's potential energy isn't increased the same amount.
Essentially, with an ideal spring, there is no way that the mass on the vertically stretched spring can be at rest in its equilibrium position B unless it is lowered there from A by the hand or some equivalent mechanical device. If it is just dropped from A without guiding it by hand, it will fly past point B, then oscillate up and down forever about B without ever coming to rest at B. Since the hand does work in moving it from A to B, mechanical energy is not conserved. If the mass is dropped from A, only then is Mechanical Energy conserved everywhere in the oscillating system, but this is not your example case. Note that mechanical energy consists of Spring and Gravity potential energies plus kinetic energy.
Rather than use energy methods, it may be best just to look at the equilibrium equation for the forces at B, then solve for the spring stiffness, k, then solve for the PE of the spring using PE = 1/2 kx^2.