At equilibrium entropy is at its maximum and the condition of equal chemical potential corresponding to the same spices in different parts of the system in equilibrium (including chemical equilibrium) follows from the restriction that entropy cannot increase beyond its maximum value. For details, consult [1] (see in particular Sec. 3.7.1, p. 51, where a closed system in considered, partitioned into two sections by a porous wall that allows particle exchange between the two sections).
[1] LE Reichl, A Modern Course in Statistical Physics, 4th revised edition (Wiley-VCH, Weinheim, 2016).
you answered your own question. its a matter of geting into an equilibrium condition. check the expression for the Gibbs free energy of the whole system.
Equality of chemical potentials is the number expression of chemical equilibrium. We describe natural phenomena using mathematical formulas. It is not logical to ask the question why formulas or equations create this or that phenomenon of nature.