It's certainly correct to say that Lee's decision to engage the Army of the Potomac at Gettysburg was in part the result of his confidence in the Army of Northern Virginia, which, by the way, had won almost every engagement against the Union army up to that point. His surbordinates, particularly James Longstreet, strongly advocated a defensive, rather than an offensive, strategy at Gettysburg, and scholars have long argued about Lee's decision to bring the two armies to battle.
Lee's decided to fight at Gettysburg for several reasons, but the most important are his firm conviction that the Army of Northern Virginia could defeat Meade's army at Gettysburg and that he might not have the opportunity again to destroy the entire Army of the Potomac in one battle. Lee knew, for example, that the South's resources--men and material for fighting--were limited and getting scarcer every month, and this realization encouraged Lee to try to bring about a victory at Gettysburg or a stalemate that might result in a negotiated settlement of the war. In other words, Lee knew the South, despite its military successes, was running out of time.
By mid-1863, Lee understood that a continued, prolonged war against the North was not a winning strategy for the South, and he felt that, at Gettysburg, he had an opportunity to defeat an entire army at one time, an opportunity that had eluded him for two years. Because both he and Meade had decent fighting positions and roughly equal numbers, Lee felt reasonably sure that the Army of Northern Virginia would be able to do what it had always done--defeat the Federals.
If Lee had agreed--as James Longstreet suggested--to leave Gettysburg after the first two days of fighting, the battle would have been considered a stalemate, not a victory for the North. When Lee ordered the attack we now call "Pickett's Charge," he made a serious tactical error that resulted in a strategic defeat for the South because it was seen as a victory for the Army of the Potomac.
With dissection of the Battle of Gettysburg, it is important to parse out as much as possible in terms for assessing the outcome. It does not do much of good to blame one element over another and to try to ascribe all of it to one element. The battle is too complex and too important for this. Accordingly, I think that there is something to be said about Lee's status in why Gettysburg had broken down in the way it did. At the time, there was overconfidence at the success at Chancellorsville, and I think that General Lee was guilty in viewing the future in the lens of the past. His thinking had to have been fortified by his own success in the past to consider that he could launch another invasion of the North via Gettysburg. I think that Lee's overconfidence led him to devalue the Union success in the West and at Vicksburg. While others were advocating retreat to Jefferson Davis, Lee spoke in favor of authorizing another attack in the North. Another invasive advance could only have been authorized because of Lee's legendary status. It's hard to imagine that Davis would have approved it had Lee not acquired the background he had and had he not used that cache in convincing Davis. Lee did not consider the fact that his troops needed supplies, therefore an advance into the North through Pennsylvania might not be wise and that his own battalions were commanded by leaders who were inexperienced for what they were about to endure. These realities were overlooked because of overconfidence and swagger about past successes being able to automatically translate into future one. Through this, I think that one can see how Lee's status and his own over-confidence played a role in the outcome of Gettysburg being so disastrous for the North. When historian Shelby Foote argues that "Gettysburg was the price the South paid for having Robert E. Lee as commander," it becomes clear that the elements of Lee's misguided sense of self and overconfidence are part of such a brutal assessment with a brutal reality.