The theorem we need is the one that says that if B and C are two contours with the same endpoints, and B can be continuously deformed to C without going outside an open set on which f is analytic, then ##\int_B\, f(z)dz=\int_C\, f(z)dz##. That is
a pretty deep theorem, but it's surprisingly easy to prove (see e.g. Saff & Snider). It follows almost immediately that if C is a closed contour, and f is analytic on an open set that contains C, then ##\int_C\, f(z)dz=0##.