How does $g$ being a generator imply Diffie-Hellman's correctness?
It does not; the equation holds for any element $g$. The fact that $g$ is a generator means only that every element of the group can be obtained a key. This is not at all necessary for the protocol.