This is not exactly a "why" question. We observe in nature that electric charge can come in varying quantities, both positive and negative; and we observe that like charges repel, whereas opposite charges attract. Therefore we must construct a theory which can describe this behaviour.
A possible restatement of the question may be "what feature of the theory of electromagnetism is responsible for describing why like charges repel and opposite charges attract?" This feature is the spin nature of the photon, which is the particle which mediates the electromagnetic force. Particles of odd integer spin generate forces which can be both attractive and repulsive, whereas particles of even integer spin only attract.