Because he was trying to keep her from being killed. He didn’t do it as punishment.
If I remember correctly the reason he told her to go was because he didn’t feel safe having her around Carl and Judith. I also thought it was completely hypocritical for him to make that decision for the group when he had done similar things himself.
If Rick was trying to help her, why didn’t he just tell her they both
would keep it to themselves. After all Rick killed Shane to protect himself.
Carol killed two to protect the group.