Mammals such as the duck-billed platypus continue to lay eggs, but they actually never really stopped.
Mammals began to evolve from egg-laying reptiles around 200 million years ago. An example of an early mammal-like reptile is Thrinaxodon. About 180 million years ago the other mammals branched off and essentially gave up laying eggs – they became the marsupials (such as kangaroos) and the placental mammals (such as cats, bats and humans). Incidentally, some reptiles have also given up laying eggs – for example boas and a number of lizards. But a few mammals have carried on laying eggs just like their reptile ancestors.
These ‘monotremes’ (meaning ‘one hole’ – they have a multipurpose hole through which they defecate, urinate and reproduce, just like snakes and birds) are now represented by just five species: the duck-billed platypus and four types of echidnas (spiny anteaters). Their eggs are rather leathery and the females don’t have nipples, but ‘sweat’ milk instead from a patch on their belly. In fact it may be that milk evolved from sweat.
As for why they never gave up egg-laying; well, if nature comes up with a design that works for the places and conditions where an animal lives, why change?
Plus, take a look at: