A black eye occurs in response to trauma. Usually you walk into a door-knob or more likely someone socks you one.
All tissue responds to injury in basically the same way with redness, swelling and resultant pain.
In medicine we use the Latin terms rubor, tumor and dolor. The swelling is in response to chemicals released from tissue after trauma that make the small blood vessels or capillaries leak fluid. The fluid occupies space in the tissue around the eye and makes the eye appear to be swollen. Although the response to trauma results in pain and a black and swollen eye the result of the response is healing of the injury which is ultimately beneficial to the eye. Hope this helps.