What causes electrical boxes to hum?
Varying (due to AC) electromagnetic forces exerted on the components cause them to vibrate thereby causing the hum. Components that typically hum noticeably are transformers (where the coils and cores vibrate/magnetostrict in the varying magnetic field), and under certain circumstances capacitors (typically they have higher resonant frequencies and audible capacitor hum is typical for electronic equipment, e.g. computers, here the forces on the plates cause the dielectric to oscillate mechanically).
The frequency of the typical hum is the mains frequency of (in Europe) $50\,\mathrm{Hz}$ or $100\,\mathrm{Hz}$ (if it is due to magnetostriction or there are rectifiers that effectively double the lowest frequency), respectively $60\,\mathrm{Hz}$ ($120\,\mathrm{Hz}$) in the US. In certain cases the most audible frequency might also be a higher harmonic (due to nonlinearity, resonance phenomena and the response of the human ear).
The mechanical oscillations due to magnetostriction double the frequency, because the length change does not depend on the direction of the magnetization (so it will have one extremum when the flux through the transformer core reaches zero and the other when the flux is maximal or minimal).
Switching power supplies make higher-pitched noise, because they rectify to DC and then drive a small transformer at much higher than mains frequency.
It's still the same root cause: magnetic forces vibrating the components, specifically the inductors. I'm not aware of electrostatic attraction/repulsion in capacitors ever being a source of noise. Capacitive microphones and piezo-electric buzzers and mics exist, but they are specifically designed as transceivers, not just capacitors.
So-called "coil whine" is common for computer parts, like motherboards, graphics cards, and main computer power supplies (that the cord plugs in to).
High-power digital logic chips internally use supply voltages between 0.8 and 1.2V these days, at high current. Different components convert the common 12V rail down to the exact voltage they're designed for. (It's not a coincidence that the supply voltage is near the band-gap for silicon. Running at as low a voltage as possible for a given CPU frequency minimizes power usage, reducing heat (which is the limiting factor in making digital logic faster these days)).