You shall put out both male and female, putting them outside the camp, that they may not defile their camp, in the midst of which I dwell.
Numbers 5:3

Lepers and defiled people are isolated from the community in Torah not necessarily because they sinned, but for the protection of the rest of the community and their relationship with God.

Ritual uncleanness isn't about dirt or disease per se. It's about contact with death or a loss of life-force. If someone is in such a state of impurity they could accidentally touch a holy object or a priest or someone en route to the altar. That could then cause a serious problem for everyone.

When God's presence is right there in the camp with the people, they need to be very cautious. He isn't looking for an excuse to zap anyone, but he's dangerous, like a highly charged capacitor. Touch it without the proper precautions and you could be killed, and it would be your own fault.