For a power connector: each pin can carry a limited amount of current. All current must return via ground. There are multiple power pins per voltage, hence multiple ground pins are needed to carry all the ground current.
For a data connector: unused pins might as well be connected to ground, and when a ribbon cable is connected, subsequent wires are alternately connected to the top and ground row, hence the ground pins end up connected to wires that sit between signal wires, which add some extra shielding between the signals.