The following diagrams show the forces (red) exerted on the blocks (blue). I have not included the forces which the blocks exert, because these are not relevant for finding the accelerations of the blocks.
I. Before the wall is removed
Let the compressive force in the spring be $T$. Both masses are in static equilibrium. The forces $F$ and $T$ are the only horizontal forces acting on $m_1$ (I assume there is no static friction) and they act in opposite directions. Therefore they are equal : $T=F$.
Likewise $m_2$ is also in static equilibrium, acted on by the spring force $T$ to the right and the reaction force $N$ from the wall to the left. Therefore $N=T=F$.
II. Immediately after the wall is removed
Your teacher is correct : the compressive force $T$ in the spring does not change instantaneously when the wall on the right is removed. The length of the spring has not yet changed at this instant in time, so the compressive force $T$ has the same value it had before.
The same 2 forces still act on $m_1$, so the resultant force on it is still zero, hence the acceleration of $m_1$ is zero.
The wall is no longer providing the reaction force $N$ which kept $m_2$ in static equilibrium. So the resultant force on $m_2$ is now the compressive force $T=F$ acting to the right. The acceleration of $m_2$ is $F/m_2$.
III. A short time after the wall is removed
After $m_2$ has accelerated and moved a short distance, the spring is now longer so the compression force in it is smaller : if has reduced from $F$ to $F'$.
The forces on $m_1$ are no longer balanced because the spring force $F'$ is now smaller than the applied force $F$, so there is a resultant force on $m_1$ hence$m_1$ now accelerates to the right at a rate of $(F-F')/m_1$.
The resultant force on $m_2$ is now $F'<F$ so the acceleration of block $m_2$ is now $F'/m_2$.