The reason why doctors advise women who have just delivered a baby to wait with sex until after bleeding stops is that there is an increased risk of infection during this time. If you have suffered vaginal tears or had an episiotomy, this risk is even greater. But, during the postpartum period, your cervix is still open to some extent, and your uterus is healing. The site where the placenta was attached offers an especially great opportunity for infections. Blood vessels are open at that site, and this takes some time to heal.
Many new parents don't even have time to think about sex while their baby is tiny, let alone actually get round to it or be in the mood. But, if you do have the desire to try sex again before lochia stops, you may be glad to hear that many midwives advise their clients to go gentle, but do the deed when they feel like it, even when a woman is still bleeding.
My midwife, who does acknowledge the possibility of infection, said that she never encountered such a thing during her long career. Using a condom may lessen the chance of infection, and will also prevent you from getting pregnant right after giving birth (yes, it can happen). Regardless of whether you wait until lochia stopped or sneak in some intimate time before that, you may want to discuss birth control options before you have sex again. And of course, make sure to stop if it is painful in any way.