First time round (Sept. 1862), he was wanting to assert Confederate viability in the eyes of the British and French, who were close to sending military aid.
Second time round (June 1863), he was wanting to relieve pressure on Vicksburg by provoking Grant into sending troops East to counter the threat of an invasion of Pennsylvania. By this time, the South was feeling its lack of supplies, and Lee was hoping to do some foraging, as well as occupying a shoe-factory near Gettysburg for the benefit of his barefoot and hungry troops. hope I helped