Lee fighting for Virginia didn’t keep him from going North to Pennsylvania or Maryland, or from going south to review port defenses after losing West Virginia.
He went north to get the fighting out of VA which had been ravaged and to supply his army from the fields and farms of Pennyslvania which were ready for harvest. and hopefully gain a military and political victory on Northern soil. He tried the same thing the year before but the lost orders stymied him. I think part of the reason he wanted to try again he learned of those lost orders and then understood why McClellan moved so quickly ( for McClellan anyway). West Virginia was still Virginia until July 1863.