Why is a white electrical wire connected to 2 black wires?
The cable with the white wire that's connected to the two black wires is a switch loop: 



Normally wires with white insulation are used only for neutrals, but code makes an exception to allow for use of the white wire in a cable used as a switch loop as a hot rather than a neutral.  

If you'll look closely in the drawing, the whites used as hots are wrapped with black tape to indicate they are being used as such.  The wiring in the picture in the question lack this, which is a code violation.  Of course the electricity can't see the tape so it's not intrinsically unsafe.  However, it can be a hazard if someone working on the wiring makes a mistake because it's not labelled as clearly as it should be.