Babies between birth and 6 months of age usually do poop while they sleep without knowing about it.
After 6 months of age a baby will usually wake up at night to poop in their diaper and then fall back asleep.
If a baby does poop at night in their diaper and they're not bothered by it and you're not bothered by the smell of the poop diaper then it's okay to leave them in the poop diaper until morning or until the baby wakes up.
Although most times and especially if the baby is in the same room as you then you'll most likely want to change the poop diaper anyway since the smell will usually be awful and keep you awake.