If I touch the output connector while standing on the ground (i am at earth potential), will I get a shock? I think yes, because the output voltage is floating and has an arbitrary voltage relative to earth? So if I touch it I can get shocked for a slight moment while the potentials are equalizing?
You might think a relatively isolated output like that has a few tens of pF, or perhaps 100 or 200 pF to ground, which if charged would give you a brief tingle. It's worse than that, because for EMC reasons, switch mode PSUs like that tend to have a small capacitor (with up to possibly nF value) between the input and output side, to attenuate SMPS-induced electromagnetic emissions. So you will get a continuous tingle.
Is this dangerous?
It should not be. The device will likely be double-insulated. That aforementioned EMI capacitor should be Y-class, which is a fail-open device.
However, were two things to go wrong in the PSU and the output to become live with a low impedance, then touching it would not be as safe as not touching it.
Can you prevent this by connecting mains earth to ground on the secondary side? By doing so, I am introducing the risk of an earth loop and polluting the output voltage?
This should be fine. The tingle current introduced by that EMI capacitor will now be shorted to mains earth ground. The output voltage should remain as good as you would expect a SMPS output to be, which can be fairly dirty in the case of a cheap USB charger supply.