Why do some appliances need grounding and some don't? E.g. my upright vacuum does (three pronged plug) while my shop vac does not (only two prongs). I am asking because I am not an EE professional.
For safety, most countries in the world require that electrical items for sale must not be dangerous even in the case of a single failure, it should take two independent failures before they can give you a shock.
All items need functional insulation to work. However, what happens if something bridges this insulation?
In Class 1 devices, all the metal parts of the appliance are bonded together, and connected to a grounded conductor. If the functional insulation fails and live touches the grounded metal, a fuse blows to remove power. You need to have both failure of the insulation, and failure of the grounding conductor, before you can get a shock. The ground conductor is an essential part of the safety, and is not required for the operation of the equipment.
In Class 2 devices, there is a second independent (supplementary) layer of insulation around the device. Both layers have to be breached before the device is dangerous to the user. This is known as double-insulated, and indicated by a 'double square' symbol on the label. This does not need further grounding for safety.
Many modern Class 2 devices have parts where two layers of insulation are not feasible, for instance the opto-coupler feedback of an offline SMPS. Here, the insulation is upgraded to reinforced insulation, which is specified and tested to a higher standard. It requires larger clearances, roughly twice those needed for functional insulation. The forward transformer is still double insulated, the primary and secondary plastic former each counting as insulation from the core.
In the US, either the appliance is double-insulated (meaning that there have to be two independent insulating strategies, both of which have to fail before you can touch 120V), or it needs to have a grounded metal casing.
An example of double insulated is a clock radio that has a transformer that isolates the low-voltage side from the high-voltage side for one strategy, and that has all the circuitry inside a plastic casing, with plastic buttons, for the other strategy.
But this is a legal thing, so it'll vary by jurisdiction and when the appliance was built.
Very nice answers, but the answer is all with a metal casing. Very nice example is any Macbook or metal phones. Macbook has 110 V of alternating current (between absolute Earth ground and ground of device, of course) while charging unless it is grounded (and you need a different USB-C PD adapter's cable (oogh) for this, British has a catch, even though its plug is grounded, there IS NO connection inside so it is not (!)). It was a very crazy revelation... Here is an article, BTW. https://habr.com/ru/company/ruvds/blog/502068/ So, ground your Macbooks, please.
Metal phones and tablets too, so please use grounded PC's USB-C PD, PC can also have up to 98% perfect PSUs! See Titanium 80 plus spec, or even more modern GaN PSUs (I have first one efficiency is 95% on 400 W out of 850 W load, that is nuts).
Of course there is a way to do proper separation. It is done by isolation transformer. But they are very big. Any SMPS is not isolated.
Another example is my LG C9 OLED TV. It is model for Russia and uses not grounded cable, but even though it has ground on the other end (small lego MOLEX-like connector, LOL) and in USA there is a grounded cable, that is not used in Russian model.
There is BTW even a specific name for devices' cables and plugs that do not need grounding: Europlug! See wikipedia, as you can see it is all being compared to Europlug (UN deliberation, I suppose).
P.S. Please remember that it is a very bad idea to use grounded device without proper grounding in your house or appartment.