As the length of the string+spring is not constant, a1 is not equal to a2/2.
I do not like such questions: "what would be the initial acceleration when something changes suddenly". In case of a sudden change such factors count what we usually neglect. The mass of the pulleys and the mass of the string. The elasticity of the string.
In this problem, the spring exerts some force on the string and it takes time till the length of the spring and the spring force change. As there is force at one end of the string there must be the same, but opposite force at the other end, if the pulleys and string are really massless. That is what the problem-writer probably assumed.
The tension is built up in the string as if it was also a spring. Because of the load, its molecules depart slightly from the equilibrium position. But the "spring constant" is very high so the new tension is built up in a very short time. And also the stretching of the string is very small so we can take its length constant.
There is time needed to get the stationary forces and the "stationary" acceleration in both cases. The difference between the case with and without the spring is the duration of this time intervals.
That the tension in a spring does not disappear at once is shown nicely with slinky experiments. See:
ehild