The Rhesus factor is due to a particular mutation and is a gene which derives from our common ancestors with chimpanzees and gorillas:
The human RH locus is responsible for the expression of the Rh blood group antigens. It consists of two closely linked genes, RHD and RHCE, that exhibit 92% similarity between coding regions. These observations suggest that they are derived from a relatively recent duplication event. Previously a study of nonhuman primate RH-like genes demonstrated that ancestral RH gene duplication occurred in the common ancestor of man, chimpanzees and gorillas.1
However, not all people have the same genetic code or carry this mutation. Like lactose intolerance, which has a similar origin, only some people carry it.
The scientific explanation for this is natural selection related to toxoplasmosis: there is a big difference in the distribution of Rh- persons in Europe versus Africa, and this has a similar distribution to the prevalence of this disease.
The observed effects of RhD phenotype could provide not only a clue to the long-standing evolutionary enigma of the origin of RhD polymorphism in humans (the effect of balancing selection), differences in the RhD+ allele frequencies in geographically distinct populations (resulting from geographic variation in the prevalence of Toxoplasma gondii), but might also be the missing piece in the puzzle of the physiological function of the RhD molecule.2
So, in Africa we have almost no Rh- and our closest co-descendants (chimpanzees) are also located in Africa. Is it surprising that they also have a similar distribution of Rh factor?
Also, keep in mind the human version of the Rh genes has strong similarities with the chimpanzee mutation, but it's not exactly the same. This is strong proof of a common ancestor and of evolution.
The Rh, factors of chimpanzee blood are different from the Rh,, factors of
human blood, as proved by the absorption experiments described in the
present paper … Therefore, according to the degree of resemblance of the Rh-Hr reactions
to those of man, the apes could be arranged in the order: chimpanzee, gibbon,
gorilla, and orangutan.3
A big nod to this Biology.SE question which I used to put together this answer.
References
1 J Hered. 2000 May-Jun;91(3):205-10. Evolution of RH genes in hominoids: characterization of a gorilla RHCE-like gene.
Blancher A, Apoil PA.
2 Neuro Endocrinol Lett. 2008 Aug;29(4):475-81.
Neurophysiological effect of the Rh factor. Protective role of the RhD molecule against Toxoplasma-induced impairment of reaction times in women.
Flegr J, Novotná M, Lindová J, Havlícek J.
3 Am J Hum Genet. 1964 June; 16(2): 246–253.
Blood Groups of Apes and Monkeys. IV. The Rh-Hr Blood Types of Anthropoid Apes
A. S. Wiener, J. Moor-Jankowski, and E. B. Gordon