Let $\nu:X\to Y$ be an injective $A$-module homomorphism. Since $B$ is a flat $A$-module, we have a injective $B$-module homomorphism $$\nu\otimes_A1_B:X\otimes_AB\to Y\otimes_AB$$ Since $M$ is a flat $B$-module, we have an injective $B$-module homomorphism $$\nu\otimes_A1_B\otimes_B1_M:X\otimes_AB\otimes_BM\to Y\otimes_AB\otimes_BM$$ But there exists a natural isomorphism of $A$-modules $M\cong B\otimes_BM$, hence the commutative diagram $\require{AMScd}$ \begin{CD} X\otimes_AB\otimes_BM@>\nu\otimes_A1_B\otimes_B1_M>>Y\otimes_AB\otimes_BM\\ @V\sim VV@VV\sim V\\ X\otimes_AM@>>\nu\otimes_A1_M> Y\otimes_AM \end{CD} shows that $\nu\otimes_A1_M:X\otimes_AM\to Y\otimes_AM$ is injective. Thus $M$ is a flat $A$-module.