system
Given the following post, respond as if you're commenting on Reddit:
human
Why did mammals lose the ability to lay eggs?

I wonder why all mammals, (except monotremes) lost the ability to law eggs. What was the evolutionary benefit?
gpt
Technically we still have eggs, they're just not eggs in the same sense as what we see with reptiles or birds.

Think about it this way: fish have eggs and fish fertilise externally by ejecting both sperm and eggs into the water where they can interact. The young then develop in "eggs" in the ocean. Mammal reproduction is essentially the same, the main difference being that we live outside water and so must replicate a water environment for our sex cells to interact with, thus the reason why land animals have sex.
With reptiles and their distant relatives the birds, they lay their eggs externally with the offspring and food stored within a protective shell. Mammals on the other hand allow the young to develop internally, so they don't need a protective coat and do not have eggs similar to that of chicken eggs.

To answer you inquiry on evolutionary benefits, developing inside the mother can mean better protection for the developing young, especially if the animal lives in a social hierarchy. The other major benefit is that there is a constant, potentially unlimited source of food available to the offspring - offspring that develop outside the body are provided with a limited food source which is limited by the size of the egg. It's thanks to the benefits of internal foetuses that humans have evolved to be as intelligent as they have, because we weren't nutritionally limited by things like egg size.