You get 24 if you say Mg2+ has 8 valence electrons (its electron configuration is 1s22s22p6) instead of zero.
In that case, there are 8 in Mg2+, and 8 in OH- (6 from O, 1 from H, and and extra 1 because of the -1 charge). Therefore there are $8 + 2 \times 8 = 24$ per formula unit made of one Mg2+ and two OH-.
Some people do argue ionized Group 1A and 2A metals (above Period 2) have 8 valence electrons instead of zero, because technically there are indeed 8 electrons in the outermost electron shell and they are isoelectronic with the noble gas at the end of the previous row (e.g. in your case Mg2+ has the same electron configuration as Ne).
But I think most chemists would prefer to say Group 1A and 2A cations have zero valence electrons, that is, that the valence shell in these ions is the shell corresponding to their Period that used to have the outermost electrons. In that case, the answer to your question is that there are zero valence electrons in Mg2+ and 8 in OH-, for a total of 16 in Mg(OH)2. Note that this is slightly different from your reasoning, however.
An argument for saying Mg2+ has zero valence electrons is that if we draw the Lewis dot structure for the formula unit, I don't know anyone who would put any dots around the Mg. On the other hand, an argument for saying that it has 8 is that we frequently argue that Mg forms the Mg2+ ion because that gives it a complete octet in the outer shell. We rarely present the octet rule as requiring 0, 2 or 8 electrons in the valence shell.
I don't think the correct answer can be found in any mathematically rigorous sense, it depends on your preference in labeling, what you want to call "valence" electrons, and there are nontrivial arguments both ways.