your example
The equation of motion are:
$$m_1\,\ddot{x}_1=F_1+Z$$ $$m_2\,\ddot{x}_2=F_2-Z$$
or
$$\begin{bmatrix} m_1 & 0 \\ 0 & m_2 \\ \end{bmatrix}\,\underbrace{\begin{bmatrix} \ddot{x}_1 \\ \ddot{x}_2 \\ \end{bmatrix}}_{\vec{\ddot{y}}}=\begin{bmatrix} F_1 \\ F_2 \\ \end{bmatrix}+\underbrace{\begin{bmatrix} 1 \\ -1 \\ \end{bmatrix}}_{C_Z}\,Z\tag 1$$ the constraint equation
$$x_2-x_1=0\quad \Rightarrow \dot{x}_2=\dot{x}_1\tag 2$$
so $x_1=q_1$ is the generalized coordinate thus $\vec{\dot{y}}=J\,\dot{q}_1$
where
$J=\begin{bmatrix} 1 \\ 1 \\ \end{bmatrix}$
and eq. (1)
$$\begin{bmatrix} m_1 & 0 \\ 0 & m_2 \\ \end{bmatrix}\,J\,\ddot{q}=\begin{bmatrix} F_1 \\ F_2 \\ \end{bmatrix}+\underbrace{\begin{bmatrix} 1 \\ -1 \\ \end{bmatrix}}_{C_Z}\,Z\tag 3$$
to eliminate the constraint force $Z$ we multiply eq(3) from the left with $J^T$
$$J^T\,C_Z=\begin{bmatrix} 1 & 1 \\ \end{bmatrix} \begin{bmatrix} 1 \\ -1 \\ \end{bmatrix}=0$$
or
$$\delta x_1\,Z-\delta x_2\,Z=0$$
this is the D'Alembert'sVirtual work principle "the constraint forces dose't affect the equations of motion "
we obtain the equations of motion
$$J^T\,M\,J\,\vec{\ddot{q}_1}=J^T\,\vec{F}$$