What is this yellow component in my Samsung mains charger and what is its purpose?
It's the transformer.

But in my opinion its way too far away from the rectifier and the mains connection

That's because it's a switching supply. Mains is rectified first, resulting in about 320V DC in the two blue CrapXon caps, then this is chopped into a square wave, fed into the transformer, and rectified in the other side. The frequency is much higher than 50Hz mains, which allows a much smaller transformer and secondary smoothing caps, and lower weight and cost.
Here's a bit more detail about how a flyback power supply works.