Postpartum lochia then infection?

So here’s an odd topic, but I went through all of my three lochia stages within the month after giving birth (1 month tomorrow ), but just last week after my stage 3, lochia alba which was yellow occurred, I started spotting blood and then started heavily bleeding. I’ve been bleeding heavy for a week now, went to emerg and was told I have a uterine lining infection. I’m now on antibiotics, but why was I almost healed and then an infection spontaneously happened? How long will it take for my infection to heal and the bleeding to stop? And what could have made my infection happen after I was so close to being healed? Anyone experience this or know anything please comment. Also been on antibiotics since three days ago.

Thanks in advance!