In the case of masses hanging from a pulley by a string, the tension in whole string is same, say equal to $$T.$$

As $${M_2} > {M_1},$$ so mass $${M_2}$$ moves down and mass $${M_1}$$ moves up with the same acceleration a (say). The arrangement of the motion is represented in the figure. According to free body diagram of mass $${M_2},$$ is
$${M_2}g - T = {M_2}a\,......\left( {\text{i}} \right)$$
According to free body diagram of mass $${M_1},$$ is
$$T - {M_1}g = {M_1}a\,......\left( {{\text{ii}}} \right)$$
Adding Eqs. (i) and (ii), we get
$$\eqalign{
& \left( {{M_2}g - T} \right) + \left( {T - {M_1}g} \right) = \left( {{M_1} + {M_2}} \right)a \cr
& \left( {{M_2} - {M_1}} \right)g = \left( {{M_1} + {M_2}} \right)a \cr
& \Rightarrow a = \left( {\frac{{{M_2} - {M_1}}}{{{M_1} + {M_2}}}} \right)g \cr} $$
Given, $${M_1} = 5\,kg,\,{M_2} = 10\,kg$$
Hence, $$a = \left( {\frac{{10 - 5}}{{5 + 10}}} \right)g$$
$$\eqalign{
& = \frac{5}{{15}}g \cr
& = \frac{g}{3}m/{s^2} \cr} $$
Alternative
Alternative, $$a = \frac{{\left( {{F_{{\text{net}}}}} \right){\text{system}}}}{{{\text{Net}}\,{\text{mass}}}}$$
$$\eqalign{
& = \frac{{\left( {10 - 5} \right) \times g}}{{5 + 10}} \cr
& = \frac{g}{3}m/{s^2} \cr} $$
NOTE
In a mass-pulley system, the tension in the string is always towards the pulley.