Why other forces contribute to tension in a system where there are 2 different masses hanging from a pulley?

The image above is from a tutorial on khan academy. After finishing the video I watched a few others as well to fully understand how to calculate the tension and acceleration of two hanging masses from a pulley.

I learnt that, while the original video uses a shortcut to calculate acceleration by treating it all as one system, the most accurate way to calculate tension and acceleration is to create two simultaneous equations, resolving the forces acting on each mass separately using $$F=ma$$. If you use this method to solve these unknowns in the image then the simultaneous equations looked like this: $$\text{Total force on object=Tension-weight}$$ Which leads to $$a=\frac{T-(9.81)(3)}{3}$$ $$\text{and}$$ $$a=\frac{(9.81)(5)-T}{5}$$ They are both equal to $$a$$ and as acceleration is the same for both they can be put either side of an equals sign: $$\frac{T-(9.81)(3)}{3}=\frac{(9.81)(5)-T}{5}$$When solved by rearranging I got approximately $$36.79$$.

The solving was not the problem: what I was confused by was how the tension is not just the the weight of the other mass. What else contributes to the value of tension? Is it the pulley they are resting on providing some normal contact force?

-The image is from a video on Youtube.

Your intuition that $$T = mg$$ (which $$m$$? $$m_1$$ or $$m_2$$?) probably comes from the equilibrium situation, where $$m_1 = m_2$$ and $$a = 0$$. In this case, you can check indeed that $$T = mg$$. But in general, this is not the case.
Imagine the situation where $$m_1 \to 0$$ and $$m_2 > 0$$ is fixed. In that case, this is simply a rope with a mass attached to only one side, with said mass falling in free fall. In that particuliar situation (falling mass with a rope attached to it), you can convince yourself that the rope is loose (or, more correctly, $$T \to 0$$ as $$M_1 \to 0$$). In fact, for $$m_1 \ll m_2$$, $$T \simeq 2 m_1 g$$ (and not $$m_1 g$$).