The Y capacitor provides a return path for the capacitively coupled energy from the primary to the secondary transformer inside the switched mode power supply. Without it, the secondary will float at an AC voltage equal to the SMPS's switching frequency, with respect to the mains voltage or earth.
Yes, the chargers aren't earthed. One problem is some countries have two pin sockets for many devices, which aren't earthed and the power supply circuit is designed so that it can be used the world over. The tiny shock is not harmful and it's perfectly safe, so long as the Y capacitor meets all the relevant safety standards.
The are other potential problems with Y capacitors though. One is the tiny current can damaged sensitive devices which don't have ESD protection, although this can be solved by proper design. Another problem is, if many unearthed appliances with Y capacitors are connected together, the leakage currents will add up and can then exceed the safe levels.
Removing the Y capacitor is generally a bad idea. One alternative is to connect the Y capacitor to earth or, if the mains connector is polarised, neutral. That way all the EMI will be diverted to earth and there will be no leakage current.
Another possibility is adding a screen between the primary and secondary of the transformer and connecting that to the mains rectifier, via a Y capacitor, but you'd need to rewind the transformer to do that. It's something which could be done by the manufacture but it would cost more.