What causes the adverse pressure gradient that leads to flow separation? When reading about flow separation I generally see a diagram like this:


imp source: Wikimedia commons

This shows that the boundary layer slows as it passes over the wing, eventually creating an adverse pressure gradient. The effect being more pronounced close to the wing it will cause a reversal of flow and separation of the boundary layer.

I can easily see how this leads to flow separation, but I’m unsure as to what causes the boundary layer to slow down like this. I’ve read that the effect is independent of surface friction. 

I know the air at the surface is stationary wrt the wing and its velocity increases the further away it gets. But if I look at the arrows in the diagram and select, say, the second one from the surface, it slows down as it goes along the wing, eventually reversing. At first I thought that the still air at the surface was somehow affecting it, but I don’t know how (shear stress?). But even at that, stationary air can not make it flow backwards.

So, what causes the flow closer to the surface to slow?
Friction plus pressure rise.

No, the effect certainly isn't independent of surface friction, otherwise the location and angle of attack of separation wouldn't change with Reynolds number.

First, friction will prevent the surface layer to become as fast as the outer flow in the suction peak, and once pressure rises, all air will slow down by the same amount. Now the already slower part near the wall will actually reverse because it slows down to a standstill and is attracted by the low pressure ahead.

Pressure has to rise past the suction peak in order for the air to get back to ambient pressure. The upper side suction is caused by the airfoil's curvature, and curvature  over the rear part of the airfoil is very low or even negative - that is what makes the air assume ambient pressure again.

I think you know already my slightly longer answer on that topic, but I will link to it nevertheless. Please let me know if I need to explain more!