I understand some of the benefits of male circumcision have been supported by modern medicine for it is supposed to help keep the male genitals cleaner. What I don't really realize is that now that it can be such a dangerous surgery which requires an enormous amount of precision, how it was first invented in the ancient civilizations. Moreover, I am truly amazed at how it is something that is shared by civilizations around the world. Many ancient civilizations, at different times, saw the practice of male circumcision and even made it mandatory among the people. How did people who lived in different areas in different ancient times collectively invent and insist male circumcision?
I understand some of the benefits of male circumcision have been supported by modern medicine for it is supposed to help keep the male genitals cleaner
It's a myth. The foreskin isn't "dirty". In young boys, it is fused to the glans by tissue called the balanopreputial lamina, and hence there is not even a space that any sort of dirt could collect in, unless such a space were artificially created by a caregiver's misguided attempt to prematurely force back the foreskin. In most older boys (above 10 or so, though it varies) and most adult males, the foreskin can rather easily be drawn back and washed with only a small amount of water--less than it would take to clean the scalp, the anus, the underarms, or most other body parts.
In contemporary times, the medical establishments of cultures that are already circumcising cultures tend to interpret the data in ways that support supposed health benefits male circumcision. The medical establishments of cultures that don't, interpret the data against it.
This page from the Royal Dutch Medical Association shows just what a hard stance they take against it--to the extent that they would call out another medical organization as mistaken and vociferously critique their position.
What I don't really realize is that now that it can be such a dangerous surgery which requires an enormous amount of precision, how it was first invented in the ancient civilizations.
Actually, "circumcision" is not as precise an operation as you'd think. The amount of tissue removed, and the types of tissue removed, can vary tremendously from one circumcision to the next, even in developed countries like the US.
how it was first invented in the ancient civilizations
A common myth is that it originated as a hygiene measure to keep sand out of the foreskin, but there is no evidence that this is the case. It could be the case that some of the specific initial rationalizations for this form of genital cutting varied from one culture to another, but the attenuation and control of male (and by extension female) sensuality likely plays a greater role than is often expected.
In Jewish culture, at least since the Middle Ages but plausibly even before, it was described as a way of hurting and damaging the penis to attenuate sensual pleasure. This was discussed by Rabbi Maimonides in his "Guide of the Perplexed" thusly
How can natural things be defective so that they need to be perfected from outside, all the more because we know how useful the foreskin is for that member? In fact this commandment has not been prescribed with a view to perfecting what is defective congenitally, but to perfecting what is defective morally. The bodily pain caused to that member is the real purpose of circumcision. None of the activities necessary for the preservation of the individual is harmed thereby, nor is procreation rendered impossible, but violent concupiscence and lust that goes beyond what is needed are diminished. The fact that circumcision weakens the faculty of sexual excitement and sometimes perhaps diminishes the pleasure is indubitable. For if at birth this member has been made to bleed and has had its covering taken away from it, it must indubitably be weakened. The Sages, may their memory be blessed, have explicitly stated: It is hard for a woman with whom an uncircumcised man has had sexual intercourse to separate from him. In my opinion this is the strongest of the reasons for circumcision.
(Maimonides, Moses. The Guide of the Perplexed. Translated by Shlomo Pines. Chicago: The University of Chicago Press, 1963. P. 609)
Similar rationales relating to attenuating sensuality were a major force in the initial popularization and normalization of male circumcision in the Anglosphere, which was prior to the late 19th century a non-circumcising culture.
Follow-up question: was it widespread among ancient peoples? Does it have multiple, independent origins? I was under the impression that it all originated from Jewish practice and that it was/is, as a result, limited to Jewish people, Muslims and Americans.