Why is the combination of hydrated aluminium oxide and magnesium hydroxide used to treat heartburn?
Hydrated $\ce{Mg(OH)2}$, aka milk of magnesia, is an osmotic (saline) laxative, as well as antacid.

$\ce{Al(OH)3}$ is also an antacid, but has the opposite effect on the bowels: it's costive, i.e. a binding agent. Aluminum has also been linked (with much uncertainty!) with Alzheimer's disease, so it has become less popular as an antacid.

The combined effects of $\ce{Mg(OH)2}$ as laxative and $\ce{Al(OH)3}$ as a costive might tend to counteract each other, so as to avoid interfering with colonic function.

However, it would be far simpler to use $\ce{CaCO3}$ as an antacid, unless the release of $\ce{CO2}$ bubbles or excess calcium in the diet is an issue.