See also this question Why do some turbofan blade have forward swept tips?, Although the answer given is a little vague and the question specifically around the tips. I will do my best to explain, but I am not a turbomachinery expert.
A compressor (or a fan) rotor stalls due to the breakdown of the tip leakage vortex or TLV (a bit like a wingtip vortex on an aircraft, caused as flow 'leaks' between the blade tips and the casing, spilling from the pressure to the suction side of the blade) at a certain blade, when this vortex breaks down its wake is incident upon the following blade, producing nasty recirculation zones, and stalling that blade. This leads to the development of stall cells, and potentially a compressor surge: the loss of steady mass flow through the rotor, (and therefore the thrust from the engine). Obviously, this is to be avoided. A modern turbofan engine however must operate over a wide range of flow velocities and densities, and so without the use of a variable geometry nozzle, keeping stall margins sufficiently wide is a huge challenge.
Because the blade tips in a fan are supersonic, there is a shockwave at the blade tip, which can exacerbate breakdown of the TLV, and so help induce a stall. It was discovered (see Bergner et al 2005) that sweeping the tips forward increased the distance between the shock and the TLV origin, decreasing their interaction and delaying breakdown of the vortex (hence, increasing stall margin). There are further effects to do with the boundary layer (forward sweep reduces the interaction between shock and BL), but that is well beyond my understanding.
In terms of back sweep nearer the hub on blades, this achieves the same ends as on transonic airliner wings: reducing the effective mach number of the incident flow, and delaying the formation of shockwaves on the fan blades, however, the downside is it adds a radial element to the flow velocity, and tends to push air outwards towards the tips, which could be detrimental to tip stall, so as always, everything is a balance.
The reason this has only been done recently, is simply: computing. High fidelity 3D CFD for rotors has only been around for a few decades, and so only now can turbomachinery engineers consider the aerodynamics of an entire blade, and even an entire rotor, rather than simply optimising airfoil sections in 2D. For a good overview of the various different factors around blade design this pdf is very helpful: https://rb.gy/kw5de
hope this is helpful.