When sexual reproduction first arose, it was among equals. All the haploid cells were pretty well identical in every way. Many species of green algae still reproduce this way. But that's not the system that humans use. What happened?
The first issue was resources. When a multicellular creature creates haploid cells, it can make a small number, or a big number. If it makes a lot, then it can't afford to spend much on each one. If it makes very few, then each one can have a big investment. A bigger thing does not travel as easily, so it makes sense for the small, numerous form to do the traveling. Some will travel to the wrong places, but they were cheap.
Living things aren't exact. Some of the creatures would have produced organs or cells that were bigger or smaller than usual. This allowed a size asymmetry to get started, and the asymmetry helped, so it became more extreme as time passed. Today, a male creature may give off millions of sperm, and an ostrich bundles an immense amount of food resources with each egg cell. The sperm do all the dangerous travelling. Eggs are guarded and protected.
So, these species lost the idea of two equal haploid cells merging. Instead each species acquired "male" and "female" sex cells, which generated what we now call sperm cells and egg cells. This does not mean that there must be "males" or "females". There is no reason why one creature can't have both "male" and "female" sex cells. Snails work that way today: they are hermaphrodites. Some trees have both male flowers and female flowers. Some fish can change from female to male.
However, humans use a simple genetic scheme whereby some offspring grow only male sex cells, and some grow only female sex cells. The chemical cues which control this difference also cue some other bodily specializations.
In the last billion years, the bodily specializations have become increasingly intricate. Many sea creatures just expel clouds or ropes of eggs into the ocean. Some glue them to a surface. Amphibians learned to live on land, but returned to water to lay eggs. Reptiles worked out a way to lay fertilized eggs on dry land, by surrounding the eggs with food and a leathery membrane. (Birds then added a hard outer shell.) Mammals worked out a way to keep the fertilized eggs safe inside the mother without her "rejecting" the partly foreign tissue. (Marsupials don't have the anti-rejection trick.)