nice question (I'm just being formal). Things are not as simple in real life, bwoy...
The reason the teacher did mg-T is because that there is a limit to which the string can hold. In real life , you obviously would not see a heavy object attached by a thin rope. That is because that "almost massless" rope does not have the tensile strength to hold the heavy object (mg>>T), where T is the maximum tension the string can hold. You already must have seen questions like "if a string can hold max. 30N then how much mass it can handle", etc. . Also, real life strings are bundles of fibre, which when get non uniformly distributed weight tend to break.
Also, by this, you might ask why things move with the third Motion. I know you
know it, but just to clarify, because it acts on different bodies, and since here
such a huge force acts on the string , it breaks. If the string can withstand the force, the system is stable. You are simply just questioning the tensile strength of the string.
I know you Raje,please don't pounce to attack me with your comments all of a sudden, just read and understand what I just said (wrote?) and then react. If you want me to explain this you can always contact me.