dB formula when input and output resistances are equal
$$P = { E^2 \over R }$$
so
$${{E_o^2 \over R} \div {E_i^2 \over R}} \implies {E_o^2 \over E_i^2}$$

This only works in the special case that \$(R_i=R_o)\$!

To directly address your question, voltage gain is by definition the open-circuit input and output, so resistances are infinite/not considered.

This goes back to the 2-port model and stuff like that.