Let $A,B$ be associative rings with $1$. Let $X$ be a right $A$-module, $Y$ an $(A,B)$-bimodule, and $Z$ a left $B$-module. Then the obvious functorial morphisms
$$
(X\otimes_AY)\otimes_BZ \rightleftarrows X\otimes_A(Y\otimes_BZ)
$$
are inverse isomorphisms.
Here are two references:
Bourbaki, Algèbre, II.3.8, Proposition 8, p. 64.
Cartan-Eilenberg, Homological algebra, II.5, Proposition 5.1, p. 27.
EDIT. Cartan and Eilenberg don't really give a proof. It doesn't seem easy to find an online proof. So, I thought it might be worth writing such a proof here. I looked at Bourbaki's and Atiyah-MacDonald's proofs. The one below is closer to Atiyah-MacDonald, but I think things get more transparent when one zooms less on the objects themselves, and more on the functors they represent.
Let $A$ and $C$ be rings, let $X$ be a right $A$-module, $Y$ an $(A,C)$-bimodule, and $Z$ a left $C$-module. We must show that there is a (unique) $\mathbb Z$-linear morphism
$$
\left(X\ \underset{A}{\otimes}\ Y\right)\ \underset{C}{\otimes}\ Z\to
X\ \underset{A}{\otimes}\ \left(Y\ \underset{C}{\otimes}\ Z\right)
$$
satisfying
$$
(x\otimes y)\otimes z\mapsto x\otimes(y\otimes z).\tag1
$$
Let $M$ be a $\mathbb Z$-module. Let $B$ be the $\mathbb Z$-module of those $\mathbb Z$-bilinear maps
$$
b:\left(X\ \underset{A}{\otimes}\ Y\right)\times Z\to M
$$
which satisfy identically $b(\tau c,z)=b(\tau,cz)$, and let $T$ be the $\mathbb Z$-module of those $\mathbb Z$-trilinear maps
$$
t:X\times Y\times Z\to M
$$
which satisfy identically $t(xa,y,z)=t(x,ay,z)$ and $t(x,yc,z)=t(x,y,cz)$.
Consider the $\mathbb Z$-linear map from $B$ to $T$ which attaches to $b$ in $B$ the element $t$ of $T$ defined by $t(x,y,z):=b(x\otimes y,z)$.
Given a $t$ in $T$ we'll define an element $b$ in $B$ by a construction inverse to the one in the previous sentence.
Pick a $z$ in $Z$, and form the $\mathbb Z$-bilinear map
$$
b_z:X\times Y\to M
$$
given by $b_z(x,y):=t(x,y,z)$. One checks that $b_z$ induces a $\mathbb Z$-linear map
$$
\ell_z:X\ \underset{A}{\otimes}\ Y\to M,
$$
and that $b(\tau,z):=\ell_z(\tau)$ fits the bill.
Put
$$
F(X,Y,Z):=\left(X\ \underset{A}{\otimes}\ Y\right)\ \underset{C}{\otimes}\ Z,\quad
G(X,Y,Z):=X\ \underset{A}{\otimes}\ \left(Y\ \underset{C}{\otimes}\ Z\right).
$$
The above observations provide a functorial isomorphism
$$
\text{Hom}_{\mathbb Z}(F(X,Y,Z),?)\simeq\text{Hom}_{\mathbb Z}(G(X,Y,Z),?).
$$
Yoneda's Lemma gives then a functorial isomorphism $F\to G$, and one easily verifies that it satisfies (1).