From a January 1861 letter to his son Custis:
"Secession is nothing but revolution. The framers of our Constitution never exhausted so much labor, wisdom and forbearance in its formation, and surrounded it with so many guards and securities, if it was intended to be broken by every member of the Confederacy at will. It was intended for 'perpetual union' so expressed in the preamble, and for the establishment of a government, not a compact, which can only be dissolved by revolution, or the consent of all the people in convention assembled. It is idle to talk of secession."
It's pretty clear that Lee did think it was illegal. He may have thought that Virginia had no other choice, but that's not the same as believing the actions were lawful.
OK...I stand corrected....however, it wasn’t illegal regardless.