It is not illegal to have a baby but it illegal to make someone who is still a child pregnant. The fault does not lie with the person who is pregnant. As far as the law is concerned, people who are not adult are not able to consent to intercourse and so it is regarded as rape. The young person in question may have said yes but that does not mean it was not rape as they are deemed unable to make an uninfluenced decision (i.e. can be manipulated) as minors, just like they cannot yet vote. It is vital to remember that rape is never victim’s fault and that this law is there to protect young adults (teenagers) and children.
The main reason is maturity and development – if the person is young they may be less able to handle the pressures and responsibilities of being a mum/dad. The age for defining this varies from country to country, and there’s no definite answer.
Humans are quite unique that it takes us so long as we develop as children and teenagers before becoming capable of parenthood. For most animals, they happens much faster. This is most likely to be determined by brain development – ie we grow and become mature so slowly because our brains are more complex than other animals’ ones. However, this is only a general trend: birds for example have very short generation times and develop quickly, and yet many of them can use tools like twigs to get food.
For understanding human and primate evolution, estimating generation time – ie the time at which we tend to have babies – is very important. For example, chimpanzee mums are about 25 years old on average, and dads about 24. And for gorillas, mums and dads are generally about 19. But the age range of having babies for chimps is very wide 9-45! And for gorillas too 7-38! So by understanding historical times at which mums/dads had babies lets us time the rate of evolution better. However, in modern times, other things like education, freedom and other opportunities make this different.