Why AC power plugs have three pins
To power a device, current has to flow thru it.  That means it has to go in one place and come out another, which requires two wires.

The third wire of most outlets is a safety ground.  It is not necessary to power a device, but can be useful to some devices.  Any device that has a conductive outer shell is a potential safety hazard.  It would only take one fault to make the shell live, like the hot wire breaking or slipping off some mounting, then touching the inside of the case instead.

In general, we try to keep users two independent faults from danger.  The above example of the hot wire coming off and touching the chassis is just a single fault.  Now the chassis is at lethal voltage, and you don't even know this until you touch it and something grounded.  Then its too late.

In such cases, the chassis is tied to the ground line.  If the fault described above happens, hot is shorted to ground, which will cause a lot of current to flow and trip the breaker.

When the outer shell of a device is made of insulating material, the user can touch it no matter what went wrong inside.  Such devices don't require a ground connection, and there's often no place to connect it anyway.  Usually such devices are "double insulated".  That means the hot voltages are normally insulated with insulation on the wire and the like.  Nothing on the hot side is supposed to rub up against the case without a deliberate layer of insulation in between.  Then you still have the case if that layer fails.

Another reason for the ground connection is to allow devices to reduce both conducted and radiated emissions.  Most line filters are common mode chokes, also called baluns, with capacitors to ground on the line cord side of both AC lines.  The balun increases the impedance of the unwanted signals, then the capacitors shunt the signals to ground.  This isn't possible without a ground connection.