Proof (residue theorem)
Finitely many poles with non-zero winding number
Let $A$ be the set of poles with non-zero winding number, and suppose $A$ is infinite.
Since winding number is locally constant, $V = \sb{z\in \C}{I(γ; z) = 0}$ is open. Therefore $\C \setminus V$ is closed. Moreover $\C\setminus V$ is bounded, since everything outside a disk containing $γ$ has zero winding number. Thus by sequential compactness, $A\subseteq \C\setminus V$ has an accumulation point $a^\ast$.
$f$ is meromorphic (in particular singularities are isolated), so $a^\ast\in \partial U$. However $U$ is open, so $a^\ast \not\in U$. Since $γ$ is homologous to zero in $U$, $a^\ast \in V$. But it is impossible for $A\subseteq \C\setminus V$ to have an accumulation point in an open set $V$.
Residue theorem
Let $p_n$ be the principal part of $f$ at $z=a_i$. Since $z=a_n$ is a pole, $p_n$ is a polynomial in $1/(z-a_n)$, say $$ \begin{align*} p_n(z) = \sum_{l=1}^{k_n} c_{ln} (z-a_n)^{-l}. \end{align*} $$ Note we have $$ \begin{align*} \oint_γ p_n(z) \d z ={}& \sum_{l=1}^{k_n} c_{ln} \oint_γ (z-a_n)^{-l} \d z \\ ={}& c_{1n} \oint_γ \frac{1}{z-a_n} \d z + \sum_{l=2}^{k_n} c_{ln} \underbrace{\oint_γ\dd{z}\frac{(z-a_l)^{-l+1}}{-l+1} \d z \\}_{0 \text{ by FTC}} \\ ={}& 2πi\,I(γ; a_n)\Res_{z=a_n} f(z). \end{align*} $$
Now define $$ \begin{align*} g(z) := f(z) - \sum_{n=1}^m p_n(z), \end{align*} $$ which is holomorphic on $U':=U\setminus \set{\text{poles of winding number 0 for }γ}$. Moreover $γ$ is homologous to zero in $U'$. Therefore by Cauchy's theorem, $\oint_γ g(z) \d z = 0$. Thus $$ \begin{align*} \oint_γ f(z) \d z = \sum_{n=1}^{m} \oint_γ p_n(z) \d z = 2πi \sum_{n=1}^{m} I(γ; a_n) \Res_{z=a_n} f(z) \end{align*} $$ as required.