According to the question, in the first condition
$U_{1}=\frac{1}{2} k x_{1}^{2}$ ...(i)
In the second condition,
$U_{2}=\frac{1}{2} k\left(x_{1}+x_{2}\right)^{2}$ ...(ii)
Increment in the potential energy
$=U_{2}-U_{1}$
$=\frac{1}{2} k\left(x_{1}+x_{2}\right)^{2}-\frac{1}{2} k x_{1}^{2}$
$=\frac{1}{2} k\left(x_{1}^{2}+x_{2}^{2}+2 x_{1} x_{2}\right)-\frac{1}{2} k x_{1}^{2}$
$=\frac{1}{2} k\left(x_{1}^{2}+x_{2}^{2}+2 x_{1} x_{2}-x_{1}^{2}\right)$
$=\frac{1}{2} k\left[2 x_{1} x_{2}+x_{2}^{2}\right]$
$=\frac{1}{2} k x_{2}\left(x_{2}+2 x_{1}\right)$