Why does $dG < 0$ imply that processes involving chemical reactions are spontaneous? Here is a short proof/derivation of why $dG < 0$ implies that a process is spontaneous (for constant temperature and pressure):

But this derivation assumes that only mechanical work is done on the system. If the process involves chemical changes the expression for internal energy becomes:
With this expression for $dU$ the last step in the derivation no longer holds: since $dG = dQ - TdS + \sum_i \mu_iN_i \neq dQ - TdS$, $dQ < TdS$ is not equivalent to $dG < 0$. It seems to me like there could be a hypothetical process for which $dG < 0$ but where $dQ > TdS$. With a process like that, the total entropy change (the environment plus the system) is negative (i.e. it is impossible). Yet, $dG < 0$ is commonly used by chemists as a criterion for the spontaneity of chemical reactions. What am I missing?
 A: 
But this derivation assumes that only mechanical work is done on the system.

The derivation does assume that the only form of work done is PV work. You object that this assumption is invalid if chemical changes occur. But chemical changes are not "work", so this assumption does not undermine the conclusion.
Your expression for $\mathrm{d}U$ is correct, but there is nowhere in the derivation where you can actually use it. It does not imply that $\mathrm{d}U$ is anything other than $\delta Q - P \, \mathrm{d}V$, so the rest of the derivation is still valid.
In effect, you are making a statement about what $U$ is "made of": chemical energy is one of the components. That's true, but this derivation doesn't make any assumptions about what $U$ is made of.
A: Indeed the derivation assumes that only mechanical work can be done on the system, and no transfer of particles and associated energy can happen; it is in the first sentence, "no matter can come in or out".
This does not mean chemical changes inside the system are forbidden; instead, they can happen but they don't affect the fact that the system is closed and don't contradict the assumption that only mechanical work is possible.
So the derivation is correct even if internal changes of chemical composition happen.
On the formal aspect: the derivation uses the expression
$$
dU = dQ - PdV
$$
which is valid due to assumptions. But it does not use your expression for $dU$ in terms of $dS,dV,dN_i$, so there is no problem with the derivation, even if $N_i$ change due to chemical processes.
A: We have, for the Gibbs free energy $G=\sum_i \mu_i N_i$ for species $i$ with numbers $N_i$ and chemical potentials. For a set of reactions denoted in stoichiometric notation
$$
\sum_i \nu_i X_i -\sum_f \nu_f X_f = 0
$$
and imposing conservation of species: $\frac{dN_i}{\nu_i} = dN = -\frac{dN_f}{\nu_f} = $ constant for all $i$ and $f$, yields
$$
dG = dN \left(\sum_i \mu_i \nu_i - \sum_f \mu_f \nu_f \right).
$$
For reactions that proceed "from left to right"
$$
\sum_i \mu_i \nu_i > \sum_f \mu_f \nu_f.
$$
where $i(f)$ denotes initial (final) reactants. For these reactions $dN<0$, implying $dG<0$.
