this is because, some rays are incident on the other surface with greater than the critical angle of the two surfaces. then total internal reflection takes place otherwise the rays incident with less than the critical angle refract.
total internal reflection:
when light ray is going from denser to rarer medium, it bends away from the normal.
for a certain angle of incidence(critical angle), the refracted ray gazes through the surface separating the two medium,ie the angle of refraction is 90 as shown in the figure.
if the angle of incidence is more than the critical angle then light ray reflects back totally. this is called total internal reflection.
similar kind of qs are anwered earlier also. refer to that.