Lee didn’t exactly quit the US Army and take up a commission with the CS Army the next day.
He resigned from the US Army. He was then persuaded to take up leadership in what was the then-equivilant of Virginia’s National Guard. Which he saw as being defensive in nature.
He was only persuaded (and “persuaded” is the right word to use) to join the CS Army (first as a military advisor and then field commander) because he saw it is the only way to effectively defend Virginia.
Even his two invasions of the North were largely defensive in nature. A primary goal of the campaign that led to Gettysburg was to get the Union Army out of the Shennandoah Valley during the planting season and resupply the Army of Northern Virginia from Pennsylvania farms. While the Battle of Gettysburg was a major military defeat, when it came to those other goals it was actually quite successful.
In any event, historians now consider that with the passage of time, Lee became more of a dedicated, convinced Confederate, less reluctant and more determined. Indeed, it would have been surprising, if commanding an army and sending men into battle, if he wasn't committed to the cause. But when we take the full measure of the man, we have to consider who he was and what he believed when the war was at its high point, as well as who he was and what he may have believed in 1860 or 1870.