Flamegrilled - The fundamental difference between male and female is how much their sex cells contribute to the offspring.
Beings made of eukaryotic cells - stuff that isn't bacteria or archaea, have numerous organelles that are outside the nucleus of our cells. Crucially we have mitochondria that produce energy. Originally mitochondria were free living organisms that formed a symbiotic relationship with one of our very distant ancestors. It became enclosed within the cell membrane in a process known as endosymbiosis - discovered by Lynne Margulies.
Mitochondria have their own DNA that is crucial to their function. It is vital that the few genes that are still retained in our mitochondria work in sync with the rest of our genome. For this reason the mitochondrial DNA is donated by just one parent - the one we call female. It may be that this is also the reason why egg cells are culled at an astonishing rate by females. If they don't pass muster they don't get to ovulate. The embryo starts with 6 million eggs of which only 300 or so will be ovulated.
So our fishy ancestors had an evolutionary choice. do they produce lots of sex cells containing just the genome or do they produce fewer cells complete with vital organelles such as mitochondria? Some went one way - we call them males; some went the other and we call them females.
The plumbing for internal fertilisation evolved later step-by-step. Just like the evolution of eyes, the intermediate steps can be found in the living world.
See "Power, Sex and Suicide" by Nick Lane for much more detail.