the capacitor is partly to make a low impedance path for "bad boy" high frequency noise to return back to the primary of the power supply.
But also the Y cap has a noted leakage current level....in other words, it basically has a resistor in parallel with it (effectively.). This is very important as it stops the secondary from getting induced up to the highest peak voltage that exists in your system (usually mains peak).
At a big global TV company, we used to augment this effective resistor with an actual 1 megohm resistor in parallel with the y cap.....so as to discharge the secondary.
When you went for coffee break people would sneek to your bench , and snip off the 1 meg resistor, and when you came back and started testing, you would touch the components on the secondary as before in order to see how hot they were getting, and would get a nasty capacitive electric shock due to the removal of the 1 meg resistor....then everyone would start laughing. This is a TRUE story.