Because of its many benefits, circumcision has been made obligatory in some religions like Islam. Some of those benefits are: prevention of infants and babies from infection of the urinal tract, penile cancer prevention, prevention of aids, etc. As for why Allah (swt) created the foreskin in the first place, it protects that part of the baby’s body, but after birth is useless, just like the umbilical cord which is cut after birth. Further benefits will most probably also be discovered as science develops.
Circumcision refers to the removal of the foreskin which is located on the head of men’s reproductive organ that stretches to its tip. Because of its many benefits, it has been made obligatory in some religions like Islam. It is also practiced by many Westerners, and one can find the reason for such in its great benefits. A small search on the internet and in medical websites is enough to find out why Islam has made such an act wajib. Such websites state that:
The most significant benefit of circumcision is prevention of urinary tract infection (UTI) and its bad outcomes; outcomes that may result in the damage of the kidneys and maybe even their failure. Studies have shown that 75 percent of infants under 3 months of age who suffered from UTI were boys, and that 95 percent of these boys weren’t circumcised. This means that if a boy isn't circumcised when born, the chances of him getting UTI in the first year of his life increase by ten times. Dr. Simfurush, a surgeon at Shahid Beheshti Medical University says: “The best thing that can be done for an infant suffering from UTI is to circumcise him.” Circumcision in adulthood also bears many benefits, namely that it protects him from aids. The significance of this benefit is so high that it has resulted in circumcision being considered one of the ways of aids prevention in African countries. This is because it has been proven that if ten circumcisions are done in a society, one person will be saved and protected from aids.
Prevention of aids isn't the only benefit though, since the area where the foreskin is located is a good place for the growth of different bacteria and viruses, circumcision makes for a good means of prevention of sexually transmitted diseases.
Another benefit is prevention from cancer. Proof for this claim is the fact that in India, where circumcision is uncommon, the rate of penile cancer is 10 times of what it is in countries in which it is a common practice, such as Denmark.
As for the reason why this body part was created in the first place, one must say: “There are definitely benefits for it for the baby before birth and even if we assume that nothing has been discovered till today, we can be sure that as science develops, the reason for it will be discovered.
It has been said that one thing it does is protect that part of the fetus’s body before birth, although it becomes useless after birth, as is the case with the umbilical cord after birth which is cut off.
 Tawdihul-Masa’el, vol. 2, pg. 953.