On the "What was Lee thinking?" aspect of Pickett's Charge:
There are lots of reasons, strong reasons, why Pickett's Charge failed and should not have been attempted. Lee was clearly over-optimistic in his view of the situation. Criticisms about the attack are many and most of them are valid. But if you want to evaluate Lee's thinking, you need to look at what he saw, not all the many problems that have been re-hashed so many times.
So, what would have happened if Pickett's Charge had worked? What was Lee seeing that led him to take this risk?
To start, we know that Lee believed the AoP could not possibly be all up to Gettysburg. The "Fishhook" position concealed Meade's rear areas from Confederate observation behind the Round Tops-Cemetery Ridge-Cemetery Hill-Culp's Hill position. Meade's flanks were secured by a cavalry division at each end and Lee has little cavalry available; even worse, Stuart himself does not arrive until Noon on July 2nd, and to Lee "cavalry" means "Stuart", because Stuart handled the recon, analysis and interrogation functions for the ANV. Lee thinks some large part of the AoP is not there yet (say V Corps and a good part of the Artillery Reserve for an example); Lee may think the AoP will also be short on artillery ammo. Given that, Lee may think that the AoP defense will be like an eggshell, that he will find the inside soft and gooey if he can crack the shell.
Next, we know that Lee has dispatched Stuart and his cavalry eastwards, to get behind the Union right flank. IRL, they are unable to do much, with Gregg and Custer doing a good job of holding them off. We see lots of speculation about why they were there and what Lee wanted them to do, often with the thought that Stuart was supposed to charge from that direction as Pickett hit the Union center. But that would be a bizarre thought for Lee, who never seems to have done anything like that (mass cavalry charge against infantry and artillery) with cavalry anywhere else. So why is Stuart out there?
Clearly Lee over-estimated the effect his bombardment would have. His artillery was not up to this task, for several reasons. Colonel Alexander was a bit sheepish about the performance, thinking of how his old instructors on the Union side would evaluate it. Confederate munitions/training/etc. were not good enough. Long range ammo was running short. Command structure for the artillery was being improvised and was disjointed. Despite that, Lee clearly expected a better performance. I doubt what he wanted was realistic in hindsight, but the ANV artillery should have done a bit better.
Lee seems to have been unaware of just how badly A. P. Hill's men had suffered in the first two days until he rode through them on the 3rd. This attack needed more strength and more support, but Lee may have thought his attack would be a bit larger than it was, and expected better support. Let's say he thought the attack would be stronger by another 1500 men than it was. He over-estimated what his men could do, and he may have over-estimated how many of them there were at this point.
So we have Lee believing that Meade would only get stronger, thinking that a delay worked against the ANV, and frustrated by the disjointed performances of July 1 and 2 with all their lost opportunities. He knows the AoP has been hit hard. He feels a hard knock might break them. Whatever else, the massive bombardment that precedes the attack is the greatest artillery preparation of the war, paving the way for a very strong attack.
So, given all that, what was Lee thinking? What did Lee see that made him push this risky attack? If did Lee think he could break them, what did he see would happen after Pickett pierced their center?
Here is what I think.
Lee saw the weakness of the "Fishhook" and the Union forward position at Gettysburg. His attack was aimed at exploiting that weakness. If he had -- somehow -- made it work, Meade and the AoP would have been in deep trouble.
To see that, you need to look at what would happen if Pickett had -- somehow -- broken through and thrown the Union center into chaos. If Meade cannot re-establish the center of the line, what does he do?
There are only two ways for the AoP to retreat from the "Fishhook" position.. One is down the Baltimore Pike; the other is down the Taneytown Road. These two roads diverge from each other, so the parts of the AoP will get farther and farther apart as they move down them. This creates the opportunity for Lee to concentrate against one or the other in pursuit, to defeat them in detail..
If Pickett breaks through, the Taneytown road will be immediately cut by his advance. The Baltimore Pike is not much further and might be cut as well by Pickett. All Union troops on Culp's Hill-Cemetery Hill and the northern end of Cemetery Ridge have just been cut off from the rest of the AoP and are about to be surrounded.
If this happens, Stuart's position to the East suddenly makes a lot of sense. He can strike at the Baltimore Pike out by Rock Creek. Confederate cavalry can turn the Pike into a chaotic traffic jam (this is where the ambulances and supply wagons are travelling). Baltimore Pike will become unusable.
This is the moment when Lee would have to wave his entire army in. He must support Pickett with everything he can. He must hit the Culps Hill-Cemetery Hill position with everything he can bring to bear. He must threaten and tie up the Union troops on the "Fishhook" to keep them from sending reinforcements to seal Pickett's breakthrough. The greatest milling maelstrom of fighting troops in the Civil War would be surging back and forth on the northern end of the "Fishhook", fighting for the salvation or annihilation of the AoP.
Even if Meade can somehow fight his way out, it will have to be by splitting the AoP and retreating in two different directions. The right will have to retreat through Stuart's cavalry on the Baltimore Pike with Confederates hitting his rear-guard and flank. The Union left will have to withdraw down the Taneytown Road under pressure. If this somehow worked out, it would be by far the worst Union defeat of the war.
I don't think Lee could have pulled this off. I do think this is what he saw, what he was thinking of when he attacked.