here m1 is going up and m2 is going down with accl a.so net force on m1 is in upward dir and net force on m2 is in downward dir.
T is the tension in the string.
for m2:the net force is in downward direction ie net accleration a in downward dir ie net force is m2a. . at a time, in m2, two forces are acting, weight in downward dir and tension of the string in upward.so this net force is m2g-T.
if you solve these equation you can get T.
but T =m2g-m2a
this comes from net force concept.