Lee was an excellent general and he had many truly excellent generals on his staff.
Lee was brilliant at exploiting the weaknesses of his opponents. It just happens that the weaknesses of his opponents were their generals. Let’s face it, the generals he went up against; McClelland, Burnside, Hooker, and most of the rest were third rate. Primarily political promotes. It’s easy to come out on top when you’re a first rate general with first rate subordinates going against the third string.
Grant and Sherman were very good generals who knew their own shortcomings and they knew how to fight and when they failed they came back even more aggressively. Never give up.
They also knew that Lee was letting his fame influence his decisions. He proved that in spades with the decisions he made at Gettysburg. He came to believe he could not be beaten and convinced his troops of the same. Overconfidence is a fatal flaw in any commander.
At Gettysburg, maybe Lee figured he needed a victory inside Northern territory because the South could not compete with the North in terms of resources and logistics.
So perhaps Pickett’s charge was a calculated gamble. If not now, when? He had to take the chance to secure a major victory because after Gettysburg and Grant/Sherman’s successes in the West, it was almost guaranteed that the South would lose.
At the start of the Civil war, the South had better senior officers, but the Union got 90% of the noncoms. That was why the Union never had the desertion problems the Confederacy had.