The forces F1 and F2 due to masses m1 and m2 respectively act on the stretched spring in opposite directions. Thus, the system as a whole is at
Thus F1 + F2 = 0
or, m1a1 + m2a2 = 0
Where a1 and a2 are accelerated of the masses m1 and m2 respectively in the opposite direction.
Now, m1a1 = -m2a2
or, a1/a2 = -m2/m1
which was to be established.