Let the system $1$ be one gas, the system $2$ be the other gas, and $P$ be the piston. The process is short enough to consider it adiabatic, so the first principle of thermodynamics gives
$$ \textrm{d}E_p + \textrm{d}U_1 + \textrm{d}U_2 = \delta W_{ext} $$
where $E_p$ is the mechanical energy of the piston and $W_{ext}$ the work done by the operator. Indeed, $\textrm{d}U_p = 0$ since the piston is a rigid body and there is no heat transfer, and $\textrm{d}E_1 = \textrm{d}E_2 = 0$ in the first order since the transformation is infinitesimal.
However, the process can be quasi-static, so $\textrm{d}E_p = 0$, so we got
$$ \textrm{d}U_1 + \textrm{d}U_2 = \delta W_{ext}$$
Here, you made the following mistake: you said that $\delta W_{ext} = 0$, but this is physically impossible. Indeed, $P_1 \neq P_2$, so the piston won't evolve smoothly at all if there's no external force applied on it. Thus, if the process is quasi-static, then there is an external force, so
$$ \textrm{d}U_1 + \textrm{d}U_2 \neq 0 $$
But we can also say that the operator doesn't touch the device. Then, $\delta W_{ext} = 0$, however the kinetic energy of the piston have changed during the process, so $\textrm{d}E_p \neq 0$, which gives
$$ \textrm{d}U_1 + \textrm{d}U_2 \neq 0$$
In both cases, at first sight the conservation of energy is violated, however once you've taken the piston into account, there's no problem anymore.