There are four cases to consider.
Case 1 Inclusion
(1.1) X-inclusion only
Suppose that w_1^X=\bar {s_1}^X=a\bar{s_2}^Xb, \ a,b\in X^* and \bar {s_1}^Y, \ \bar{s_2}^Y are disjoint. Then a_2^X=a_1^Xa and b_2^X=bb_1^X. There are two cases to consider: w_1^Y=\bar{s_1}^Yc\bar{s_2}^Y and w_1^Y=\bar{s_2}^Yc\bar{s_1}^Y, where c\in Y^*.
For w_1^Y=\bar{s_1}^Yc\bar{s_2}^Y, we have w_1=s_1^X\bar{s_1}^Yc\bar{s_2}^Y, \ a_2^Y=a_1^Y\bar{s_1}^Yc, b_1^Y=c\bar{s_2}^Yb_2^Y, w=a_1w_1b_1^Xb_2^Y=a_1\bar{s_1}ac\bar{s_2}b_2 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1b_1^Xc\bar{s_2}^Yb_2^Y-a_1^Xaa_1^Y\bar{s_1}^Ycs_2bb_1^Xb_2^Y\\
&=a_1(s_1c\bar{s_2}^Y-\bar{s_1}^Ycas_2b)b_1^Xb_2^Y\\
&=a_1(s_1,s_2)_{w_1}b_1^Xb_2^Y\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
For w_1^Y=\bar{s_2}^Yc\bar{s_1}^Y, we have w_1=s_1^X\bar{s_2}^Yc\bar{s_1}^Y, \ a_1^Y=a_2^Y\bar{s_2}^Yc, b_2^Y=c\bar{s_1}^Yb_1^Y, w=a_1^Xa_2^Yw_1b_1 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Y\bar{s_2}^Ycs_1b_1-a_1^Xaa_2^Ys_2bb_1^Xc\bar{s_1}^Yb_1^Y\\
&=a_1^Xa_2^Y(\bar{s_2}^Ycs_1-as_2bc\bar{s_1}^Y)b_1\\
&=a_1^Xa_2^Y(s_1,s_2)_{w_1}b_1\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
(1.2) Y-inclusion only
This case is similar to (1.1).
(1.3) X,Y-inclusion
We may assume that \bar{s_2} is a subword of \bar{s_1}, i.e., w_1=\bar{s_1}=ac\bar{s_2}bd, a,b\in X^*, c,d\in Y^*, a_2^X=a_1^Xa, b_2^X=bb_1^X, a_2^Y=a_1^Yc and b_2^Y=db_1^Y. Thus, a_2=a_1ac, \ b_2=bdb_1, \ w=a_1w_1b_1 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1b_1-a_1acs_2bdb_1\\
&=a_1(s_1-acs_2bd)b_1\\
&=a_1(s_1,s_2)_{w_1}b_1\\
&\equiv&0 \ \ \ \ \ mod(S,w).
\end{aligned}
(1.4) X,Y-skew-inclusion
Assume that w_1^X=\bar{s_1}^X=a\bar{s_2}^Xb, \ a,b\in X^* and w_1^Y=\bar{s_2}^Y=c\bar{s_1}^Yd, \ c,d\in Y^*. Then a_2^X=a_1^Xa, b_2^X=bb_1^X, a_1^Y=a_2^Yc and b_1^Y=db_2^Y. Thus, w=a_1^Xa_2^Yw_1b_1^Xb_2^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Ycs_1b_1^Xdb_2^Y-a_1^Xaa_2^Ys_2bb_1^Xb_2^Y\\
&=a_1^Xa_2^Y(cs_1d-as_2b)b_1^Xb_2^Y\\
&=a_1^Xa_2^Y(s_1,s_2)_{w_1}b_1^Xb_2^Y\\
&\equiv&0 \ \ \ \ \ mod(S,w). \end{aligned}
Case 2 Intersection
(2.1) X-intersection only
We may assume that \bar{s_1}^X is at the left of \bar{s_2}^X, i.e., w_1^X=\bar{s_1}^Xb=a\bar{s_2}^X, a,b\in X^* and |\bar{s_1}^X|+|\bar{s_2}^X|>|w_1^X|. Then a_2^X=a_1^Xa and b_1^X=bb_2^X. There are two cases to be consider: w_1^Y=\bar{s_1}^Yc\bar{s_2}^Y and w_1^Y=\bar{s_2}^Yc\bar{s_1}^Y,
\ c\in Y^*.
For w_1^Y=\bar{s_1}^Yc\bar{s_2}^Y, i.e., w_1=\bar{s_1}bc\bar{s_2}^Y, we have a_2^Y=a_1^Y\bar{s_1}^Yc, b_1^Y=c\bar{s_2}^Yb_2^Y, w=a_1\bar{s_1}ac\bar{s_2}b_2=a_1w_1b_2 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1bb_2^Xc\bar{s_2}^Yb_2^Y-a_1^Xaa_1^Y\bar{s_2}^Ycs_2b_2\\
&=a_1(s_1bc\bar{s_2}^Y-a\bar{s_2}^Ycs_2)b_2\\
&=a_1(s_1,s_2)_{w_1}b_2\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
For w_1^Y=\bar{s_2}^Yc\bar{s_1}^Y, i.e., w_1=\bar{s_2}^Yc\bar{s_1}b, we have a_1^Y=a_2^Y\bar{s_2}^Yc, b_2^Y=c\bar{s_1}^Yb_1^Y, \ w=a_1^Xa_2^Yw_1b_2^Xb_1^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Y\bar{s_2}^Ycs_1bb_2^Xb_1^Y-a_1^Xaa_2^Ys_2b_2^Xc\bar{s_1}^Yb_1^Y\\
&=a_1^Xa_2^Y(\bar{s_2}^Ycs_1b-as_2c\bar{s_1}^Y)b_2^Xb_1^Y\\
&=a_1^Xa_2^Y(s_1,s_2)_{w_1}b_2^Xb_1^Y\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
(2.2) Y-intersection only
This case is similar to (2.1).
(2.3) X,Y-intersection
Assume that w_1^X=\bar{s_1}^Xb=a\bar{s_2}^X, w_1^Y=\bar{s_1}^Yd=c\bar{s_2}^Y, a,b\in X^*, \ c,d\in Y^*, |\bar{s_1}^X|+|\bar{s_2}^X|>|w_1^X| and |\bar{s_1}^Y|+|\bar{s_2}^Y|>|w_1^Y|. Then a_2^X=a_1^Xa, b_1^X=bb_2^X, a_2^Y=a_1^Yc, b_1^Y=db_2^Y, w=a_1w_1b_2 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1bb_2^Xdb_2^Y-a_1^Xaa_1^Ycs_2b_2\\
&=a_1(s_1bd-acs_2)b_2\\
&=a_1(s_1,s_2)_{w_1}b_2\\
&\equiv&0 \ \ \ \ \ mod(S,w).
\end{aligned}
(2.4) X,Y-skew-intersection
Assume that w_1^X=\bar{s_1}^Xb=a\bar{s_2}^X, w_1^Y=c\bar{s_1}^Y=\bar{s_2}^Yd, |\bar{s_1}^X|+|\bar{s_2}^X|>|w_1^X|, |\bar{s_1}^Y|+|\bar{s_2}^Y|>|w_1^Y|, a,b\in X^*, \ c,d\in Y^*. Then a_2^X=a_1^Xa, b_1^X=bb_2^X, a_1^Y=a_2^Yc, b_2^Y=db_1^Y, w=a_1^Xa_2^Yw_1b_2^Xb_1^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Ycs_1bb_2^Xb_1^Y-a_1^Xaa_2^Ys_2b_2^Xdb_1^Y\\
&=a_1^Xa_2^Y(cs_1b-as_2d)b_2^Xb_1^Y\\
&=a_1^Xa_2^Y(s_1,s_2)_{w_1}b_2^Xb_1^Y \\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
Case 3 Both inclusion and intersection
(3.1) X-inclusion and Y-intersection
We may assume that w_1^X=\bar{s_1}^X=a\bar{s_2}^Xb, a,b\in X^*. Then a_2^X=a_1^Xa and b_2^X=bb_1^X. There two cases to consider: w_1^Y=\bar{s_1}^Yd=c\bar{s_2}^Y and w_1^Y=c\bar{s_1}^Y=\bar{s_2}^Yd, where c,d\in Y^*, |\bar{s_1}^Y|+|\bar{s_2}^Y|>|w_1^Y|.
For w_1^Y=\bar{s_1}^Yd=c\bar{s_2}^Y, we have a_2^Y=a_1^Yc, b_1^Y=db_2^Y, \ w=a_1w_1b_1^Xb_2^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1b_1^Xdb_2^Y-a_1^Xaa_1^Ycs_2bb_1^Xb_2^Y\\
&=a_1(s_1d-acs_2b)b_1^Xb_2^Y\\
&=a_1(s_1,s_2)_{w_1}b_2\\
&\equiv&0 \ \ \ \ \ mod(S,w).
\end{aligned}
For w_1^Y=c\bar{s_1}^Y=\bar{s_2}^Yd, we have a_1^Y=a_2^Yc, b_2^Y=db_1^Y, w=a_1^Xa_2^Yw_1b_2^Xdb_1^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Ycs_1b_1-a_1^Xaa_2^Ys_2bb_1^Xdb_1^Y\\
&=a_1^Xa_2^Y(cs_1-as_2bd)b_1\\
&=a_1^Xa_2^Y(s_1,s_2)_{w_1}b_1 \\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
(3.2) X-intersection and Y-inclusion
Assume that w_1^X=\bar{s_1}^Xb=a\bar{s_2}^X, a,b\in Y^* with |\bar{s_1}^X|+|\bar{s_2}^X|>|w_1^X|. Then a_2^X=a_1^Xa, b_1^X=bb_2^X. There are two cases to consider: w_1^Y=\bar{s_1}^Y=c\bar{s_2}^Yd and \bar{s_2}^Y=c\bar{s_1}^Yd, where c,d\in Y^*.
For w_1^Y=\bar{s_1}^Y=c\bar{s_2}^Yd, we have a_2^Y=a_1^Yc, b_2^Y=db_1^Y, w=a_1w_1b_2^Xb_1^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1bb_2^Xb_1^Y-a_1acs_2b_2^Xdb_1^Y\\
&=a_1(s_1b-acs_2d)b_2^Xb_1^Y\\
&=a_1(s_1,s_2)_{w_1}b_2^Xb_1^Y\\
&\equiv&0 \ \ \ \ \ mod(S,w).
\end{aligned}
For w_1^Y=\bar{s_2}^Y=c\bar{s_1}^Yd, we have a_1^Y=a_2^Yc, b_1^Y=db_2^Y, w=a_1^Xa_2^Yw_1b_2 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Ycs_1bb_2^Xdb_2^Y-a_1^Xaa_2^Ys_2b_2\\
&=a_1^Xa_2^Y(cs_1bd-as_2)b_2\\
&=a_1^Xa_2^Y(s_1,s_2)_{w_1}b_2\\
&\equiv&0 \ \ \ \ \ mod(S,w).
\end{aligned}
Case 4. \bar{s_1} and \bar{s_2} disjoint
For w=w^Xw^Y, by symmetry, there are two cases to consider: w^Y=a_1^Y\bar{s_1}^Yc\bar{s_2}^Yb_2^Y and w^Y=a_2^Y\bar{s_2}^Yc\bar{s_1}^Yb_1^Y, where w^X=a_1^X\bar{s_1}^Xa\bar{s_2}^Xb_2^X, \ a\in X^*, \
a_2^X=a_1^X\bar{s_1}^Xa, \ b_1^X=a\bar{s_2}^Xb_2^X and c\in Y^*.
For w=a_1^X\bar{s_1}^Xa\bar{s_2}^Xb_2^Xa_1^Y\bar{s_1}^Yc\bar{s_2}^Yb_2^Y=a_1\bar{s_1}ac\bar{s_2}b_2, we have a_2=a_1\bar{s_1}ac, \ b_1=ac\bar{s_2}b_2 and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1s_1ac\bar{s_2}b_2-a_1\bar{s_1}acs_2b_2\\
&=a_1(s_1-\bar{s_1})acs_2b_2-a_1s_1ac(s_2-\bar{s_2})b_2\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
For w=a_1^X\bar{s_1}^Xa\bar{s_2}^Xb_2^Xa_2^Y\bar{s_2}^Yc\bar{s_1}^Yb_1^Y, we have a_1^Y=a_2^Y\bar{s_2}^Yc, \ b_2^Y=c\bar{s_1}^Yb_1^Y and
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Y\bar{s_2}^Ycs_1a\bar{s_2}^Xb_2^Xb_1^Y-a_1^X\bar{s_1}^Xaa_2^Ys_2b_2^Xc\bar{s_1}^Yb_1^Y\\
&=a_1^Xa_2^Y(\bar{s_2}^Ycs_1a\bar{s_2}^X-\bar{s_1}^Xas_2c\bar{s_1}^Y)b_2^Xb_1^Y.\\
\end{aligned}
Let s_1=\sum_{i=1}^n\alpha_iu_{1i}^Xu_{1i}^Y and s_2=\sum_{j=1}^m\beta_ju_{2j}^Xu_{2j}^Y, where \alpha_1=\beta_1=1. Then
\begin{aligned}
\bar{s_2}^Ycs_1a\bar{s_2}^X-\bar{s_1}^Xas_2c\bar{s_1}^Y&=
\sum_{i=2}^n\alpha_iu_{1i}^Xa\bar{s_2}cu_{1i}^Y-\sum_{j=2}^m\beta_iu_{2j}^Yc\bar{s_1}au_{2j}^X\\
&=\sum_{i=2}^n\alpha_iu_{1i}^Xa(\bar{s_2}-s_2)cu_{1i}^Y+\sum_{j=2}^m\beta_ju_{2j}^Yc(s_1-\bar{s_1})au_{2j}^X\\
& \ &+\sum_{i=2}^n\alpha_iu_{1i}^Xas_2cu_{1i}^Y-\sum_{j=2}^m\beta_ju_{2j}^Ycs_1au_{2j}^X\\
&\equiv&\sum_{i=2}^n\sum_{j=2}^m\alpha_i\beta_ju_{1i}^Xau_{2j}^Xu_{2j}^Ycu_{1i}^Y-
\sum_{j=2}^m\sum_{i=2}^n\alpha_i\beta_ju_{2j}^Ycu_{1i}^Yu_{1i}^Xau_{2j}^X\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w_1),
\end{aligned}
where w_1=\bar{s_2}^Yc\bar{s_1}a\bar{s_2}^X=\bar{s_1}^Xa\bar{s_2}c\bar{s_1}^Y. Since w=a_1^Xa_2^Yw_1b_2^Xb_1^Y, we have
\begin{aligned}
a_1s_1b_1-a_2s_2b_2&=a_1^Xa_2^Y(\bar{s_2}^Ycs_1a\bar{s_2}^X-\bar{s_1}^Xas_2c\bar{s_1}^Y)b_2^Xb_1^Y\\
&\equiv&0 \ \ \ \ \ \ \ mod(S,w).
\end{aligned}
This completes the proof. \square