It is just not a reversible process.
Calculations for the irreversible sequence
Say the piston has an area $A$, the two masses are $m$ and $m'$, and the initial state of the gas is characterized by:
$$V = V_0,$$ $$P = P_0 = P'_e = (m + m') g / A,$$ $$T = T_0.$$
with $P'_e$ the external pressure applied to the piston when both masses $m$ and $m'$ are present.
When the mass $m'$ is removed, the gas, at initial pressure $P_0$ expands against the new external pressure $P_e = m g / A < P_0$, doing a work $W = -P_e \Delta V$ until it reaches the new state: $$V = V_f,$$ $$P = P_f = P_e,$$ $$T = T_f.$$
When the mass $m'$ is repositioned, the gas is compressed by the new external pressure $P_e'$, doing a work $W' = - P_e' \Delta V'$.
At the end of the process, the internal energy of the gas has changed by the amount $$\Delta U = W + W' = - P_e \Delta V - P'_e \Delta V'.$$ So even if $\Delta V'$ were equal to $\Delta V$ the system is not brought back to the same state.
The crucial point here is that during the expansion and compression phases, there is a discontinuity between the internal and external pressure, and therefore an asymmetry between the expansion and the compression. This discontinuity is the reason why it cannot be considered as a quasi-static process. In fact, the term "quasi-static process" is a misnomer because what it designates it is not a process at all but a range of constrained equilibrium states. Giving this range of constrained equilibrium states determines nothing about the various actual possible processes that could navigate the system from one equilibrium state to the next.
Scenario of a reversible sequence (reversible cycle)
For the process to be reversible, the external pressure applied to the piston should always equal the pressure of the gas $P(t) = P_e(t)$ all along the transformation, with for instance $P(t)= n\text{R}T(t)/V(t)$ if it were a perfect gas. Such a process would require to "remove" the mass $m'$ very progressively.
In such a process the work done by the gas would be exactly the opposite during the compression as it was during the expansion, and the gas would then be brought back to its initial state.
Entropy increase
One might then wonder how the entropy has increased during the first irreversible sequence, since $Q = 0$ all along the process which is assumed to be adiabatic... There are two ways to analyze the situation:
The first way is to recognize, as explained in the answer by Nathaniel, that for the system to reach a static equilibrium, there must be friction happening which stabilizes the piston at each new position. If there were no such friction, the piston would keep oscillating after the mass $m'$ had been removed or after it had been repositioned.
The second way is to be aware that the relation $\text{d}S = \delta Q/T$ only applies to reversible processes. In the irreversible process, the entropy increases due to the pressure discontinuity in the composite system ($P_0 \neq P_e$). To compute the resulting increase in entropy, one would need to find a reversible process that bring the system (and its surrounding) to exactly the same final state, and evaluate $\text{d}S = \delta Q/T$ for the gas along this reversible process. Obviously, such a reversible (but computable) process would not be non-adiabaticadiabatic, but it would be computable.