Magnesium hydroxide neutralizes gastric acid in the stomach when used in antacids. Since it is insoluble in water, it does not cause any reaction until it reaches the hydrochloric acid present in the gastric juices. It combines with this stomach acid to form water and magnesium chloride, effectively reducing acidity.