This is a very good question! Although your teacher didn't go over it, however your textbook may have a "proof". Search there.
The fact that Gauss' law works for irregular closed surfaces in addition to spheres lies in the fact that they both have the same measure of "solid angle" when measured from their insides.
It is best to think of this with a two-dimensional analogue. Consider a rubber band in a coordinate system with the origin at the band's interior. Suppose we took a ray from the origin and swung it across the plane keeping it fixed at the origin. How much "angle" does rubber band take up? That is, how much angle is swept by the ray until it no longer intersects the rubber band? An entire revolution. That is, 2\pi. This is because the rubberband surrounds the origin and is closed. It doesn't matter what shape it is. It could be a circle or a hexagon or any shape as long as it surrounds the origin. If the origin lied
outside the rubber band. Then the angle swept out by the rubber band would be less than that of a revolution. Can you visualize why?
Mathematically, we would say that
\oint_\Gamma {d\phi } = 2\pi.
Here, gamma is any closed curve with the origin at the interior and phi is the angle parameter of the ray from the origin doing the sweeping.
However, this can be generalized in three dimensions. Here, we consider "solid angles." Recall that an angle corresponds to the length of an arc on the unit circle. In the same manner, solid angles correspond to the surface area of some patch of the unit sphere (total surface area = 4\pi). We then have
\oint_\Delta {d\Omega = 4\pi }.
Here, delta is some closed surface with the origin in the interior and omega is a parameter describing the solid angle. Can you visualize this?
A very special thing happens when you take the flux integral of an inverse-square field. Remember that an angle is the length of an arc divided by the radius. Similarly, a solid angle is the area of a patch divided by the SQUARE of the radius (the solid angle must be unitless.). Consider a charge
q and a closed surface surrounding it. Taking the flux of the charge's electric field through that surface, we then have (in Gaussian units)
\oint {{\bf{E}} \cdot {\bf{dS}}} = q\oint {\frac{{d{\bf{S}}}}{{{r^2}}}} = q\oint {d\Omega = 4} \pi q
I hope this helps.