It mainly has to do with the construction of the electrical device, and what safety standard the device is built to. The most straightforward construction uses a 3-prong plug, and all user-accessible metal on the outside of the package is grounded to the Earth ground connection of the 3rd prong. This is done so that if hot comes loose inside the metal package, it will contact Earth-grounded metal and blow the main breaker, without energizing the metal enclosure and posing a shock hazard to the user. Using a grounded metal enclosure also has the benefit of making it easier to pass radiated EMI testing (the tests to make sure that you aren't making so much RF noise that you interfere with broadcast radio and TV transmissions).
Devices with 2-prong plugs have stricter input insulation requirements for the hot and neutral connections. There is a class of devices called "double-insulated", where there is an extra layer of insulation and separation between the hot/neutral wires and all other circuitry in the device. So even though corded power drills have exposed metal parts that the operator can touch, the hot/neutral power input wiring has extra insulation and separation from everything user accessible, and so the ground connection is not needed.
The polarized 2-prong plugs are mainly used with light fixtures. The wider prong is the neutral, and the narrower one is for hot. This matches the polarization of electrical outlets, and is meant to keep neutral the outer connection for screw-in light bulbs, since that outer screw part is easy to touch by accident when screwing in a light bulb. The polarized plug is meant to keep the hot part of the light bulb socket just the bottom button part, which you have to be a lot dumber to reach down and try to touch.