Here the forces are mg vertically downward and Tension of the string upwards
T= Mg
Here by applying Hook's law, the tension equals to
T = Kx [ where K is the spring constant and x is the extension under equilibrium produced in the length of the spring]
Under the condition of the equilibrium Force acting in downward direction will be equal to the force acting in upward direction
So, Tension in the string = Weight of the mass
Or, Kx=Mg
Or, x=MgK
But mass will perform SHM and it will go beyond the equilibrium position and distance traveled beyond equilibrium position will be MgK
Hence, maximum extension produced in the string is 2MgK