Tension obviously is not the same throughout a massless rope.
Obviously, as almost always, everything depends on the external conditions. The basic rule is that Newton's laws have to be satisfied for every infinitesimal part of the string.
Something about curves in 2D first: For a smooth curve in two dimensions, one can define a pair of orthonormal vectors called the tangent vector $\mathbf{\hat{t}}$ and a normal/curvature vector $\mathbf{\hat{n}}$ at every point on the curve. The two are related by $$ \frac{d}{ds}\mathbf{\hat{t}} = \frac{\mathbf{\hat{n}}}{R}$$ where $R$ is the radius of curvature and $s$ is the Euclidean distance measured along the curve.
Now the force acting on an infinitesimal element of the rope of length $\Delta s$ is given by $$ \frac{d}{ds}(T \mathbf{\hat{t}}).\Delta s + \Delta\mathbf{ F}_{\text{ext}}.$$
Here $\Delta\mathbf{ F}_{\text{ext}}$ is the external force acting on the infinitesimal element.
With such a force this infinitesimal element would fly off with an acceleration $$ \bigg(\frac{d}{ds}(T \mathbf{\hat{t}})+\frac{\Delta \mathbf{F}_{\text{ext}}}{\Delta s}\bigg)\frac{1}{\mu}, $$ where $\mu$ is the mass density of the string. In the limit $\mu\to 0$, we must therefore have
$$\frac{d}{ds}(T \mathbf{\hat{t}})+\frac{\Delta \mathbf{F}_{\text{ext}}}{\Delta s}=0.$$
In this particular case, $\Delta \mathbf{F}_{\text{ext}}$ from the pulley is perpendicular to the string at every point, i.e. along $\mathbf{\hat{n}}$
$$ \implies \mathbf{\hat{t}}\cdot\frac{d}{ds}(T \mathbf{\hat{t}})=0, $$
Or equivalently,
$$\frac{dT}{ds}= 0, $$
resulting in the claim that tension is constant along the string.
If there is friction, tension changescan change exponentially even on a massless string!