Fix an inertial reference frame to the ground to observe the motion of the masses.
Let the tension in the rope be T (in fact, tension is the property of a point of the rope). In this case with ideal pulley (massless and frictionless) and ideal rope (inextensible, massless, and flexible), the tension will remain constant throughout the rope.
Let the acceleration of m2 bevertically downwards, and acceleration of m1 will also be a, vertically upwards. This is because the rope is inextensible; during motion, the length of the rope must not change, and the rope must not slacken either.
From the above statement, you must not conclude that the acceleration of the masses connected by a rope are always equal. The relationship between the accelerations of the masses depends on the configuration of the pulley-rope system, which can be obtained from the fact that the length of an ideal rope must not change and the rope must not slacken.
Using equation ∑→F=m→a for the force diagrams of m1 and m2,
T−m1g=m1a........(i)
m2g−T=m2a.......(ii)
Adding (i) and (ii), m2g−m1g=m1a+m2a
a=(m2−m1m2+m1)g.......(iii)
Substituting this value of a in (i), we get
T=m1g+m1(m2−m1m2+m1)g=2m1m2(m1+m2)g........(iv)