Why is a titration necessary? Why can't we just compare the moles of the acid and base?
Man! you must have got impure sample of Mg(OH)2
Moreover, Mg(OH)2 being sparingly soluble may not be finding a way for direct titration, so the method suggested in the problem is a process we call as BACK-TITRATION. This you have to follow i all such situations, where direct titration might not, for any of the reasons, be possible.

Because all 1 g Mg(OH)2 is not pure, you can expect incorrect answer if you are directly comparing the moles of H+ &amp; OH- ions.

Would this be fine?