I guess this is a homework/check-my-work problem, so by the letter of the law I should not answer, but I would argue there is broad interest in solving it correctly given that a supposedly reputable source is presenting an incorrect solution.
Here is how I would do this. Initially, the spring is stretched distance $d=mg/k$ below its equilibrium position. Choose the position of the hanging block as $y=0$, so the gravitational potential energy immediately after the collision is zero. In terms of the speed $v=v_0/2$ of the blocks after the collision and the mass $m$ of one block, the total energy immediately after the collision is \begin{align} E_i &= \frac{1}{2}(2m) v^2 + \frac{1}{2}kd^2\\ &= \frac{1}{4}mv_0^2 + \frac{1}{2}\frac{m^2g^2}{k}. \end{align} Let $h$ be the distance of the blocks above the equilibrium position of the spring when the blocks are at their maximum height. At this point, the blocks are at rest, so their total energy is \begin{align} E_f &= \frac{1}{2}kh^2 + 2mg(h + d)\\ &= \frac{1}{2}kh^2 + 2mgh + \frac{2m^2g^2}{k}. \end{align} Using conservation of energy, \begin{align} &\frac{1}{4}mv_0^2 + \frac{1}{2}\frac{m^2g^2}{k} = \frac{1}{2}kh^2 + mgh + \frac{2m^2g^2}{k}\\ \rightarrow &\frac{1}{2}kh^2 + 2mgh + \frac{3}{2}\frac{m^2g^2}{k} - \frac{1}{4}mv_0^2 = 0. \end{align} We can solve this quadratic equation for $h$ to obtain \begin{align} h = -\frac{2mg}{k} + \sqrt{\frac{m^2g^2}{k^2} + \frac{mv_0^2}{2k}}. \end{align} In terms of the given numbers, $v_0 = 5.0\,\text{m}/\text{s}$, $m=5.0\,\text{kg}$, and $k=250\,\text{N}/\text{m}$, we get $\boxed{h=15\,\text{cm}.}$
Note that if we set $g=0$ so that there is no gravity, we get \begin{align} h = \sqrt{\frac{mv_0^2}{2k}} = \boxed{50\,\text{cm}.} \end{align} We are left to conclude that the author of the solution was likely in free-fall at the time of its writing.