He defended his home state against what he considered an invading army.
Think of it this way:
I have the bitterest disagreement with my nation's position on abortion. That doesn't change the fact that I love my country and will - and have - defended her. I would imagine Lee felt much the same way. He was, as someone else pointed out, mildly opposed to slavery personally - which was a fairly progressive opinion to hold at the time. He was far more concerned with the fact that his native state was being invaded.
> He defended his home state against what he considered an invading army.
The South probably shouldn't have started the war, then.