Why was Lee in Pennsylvania? In his letters to Davis Lee laid out his plan for an offensive that would end in the capture of Washington. Davis was supposed to order troops guarding coastal Carolina & concentrate approximately 100,000 men under Beauregard at Culpepper VA. The dual threat of Lee coming from the west & Beauregard's threat from the south would force Hooker into pulling back to defend Washington. It was not until June 29th that Cooper wrote to Lee telling him that Davis had not ordered the movement of the regiments on the Carolina coast.
Lee had written to Davis expressing his anxiety that the dwindling numbers in the Confederate Army was well on its way to making a military victory impossible. He went so far as to advise political moves that would divide the Union electorate & create a peace party. Lee was under no illusion, he was never going to have another opportunity to go on the offensive. With Rosecrans poised to move on Chattanooga, Grant about to take Vicksburg, the sand was running out on the Confederacy. Lee had to do something big & do it now.
Lee's plan broke down right from the start. Due to the lack of reinforcements, Lee was forced to cut off his communication with Virginia. He had no illusions as to the risks inherent in an advance into enemy territory without a secure supply line or avenue of retreat. At no time in the planning for the advance into Pennsylvania did Lee plan to fight a battle to the death with the AoP. That battle was supposed to occur on the outskirts of Washington in concert with Beauregard's force. He would have had enough men to overwhelm the AoP & take Washington. There were those who thought that would end the war. Instead of fighting the war winning battle he had planned, Harry Heath blundered into Buford's cavalry in a place nobody had ever heard of & triggered a meeting engagement.
For good reason, generals avoid meeting engagements whenever possible. Units blunder into each other, arrive at random times or not at all, & the commanding general has no idea of what he is facing. A meeting engagement is a list of bad, worse & disastrous possibilities. The Battle of Gettysburg is a sterling example that proves the rule.
Lee found himself fighting a battle in a place he did not know & without the local people flocking to his HQ with intel that he enjoyed in Virginia. He literally did not know what was going on behind the hills where the AoP was deployed. Meade could shift his forces or hide reinforcements without Lee being able to see them. Because Meade had the high ground, Lee ordered Porter Alexander to be careful to maneuver the artillery to avoid the U.S. Signal Corps stations of observation that could observe the entire area. Longstreet ran full tilt into that problem on the second day of the battle.
Stuart was not with the army because his orders had been issued with the understanding that the Washington battle plan was still in action. Like everybody else, he had no reason to believe that a full blown battle with the AoP was ever going to happen. Without the threat from Beauregard at Culpepper, Hooker/Meade was free to pursue Lee into Pennsylvania. He was like one of those knights that get stuck on the wrong side of the board when an attack is stymied. I know exactly how Lee must have felt about that.
For a variety of reasons, none of them good, Lee was having a very hard time getting his commanders to do what he wanted done. Under the stress of a meeting engagement & the lack of intel, the mulish commanders must have irritated the fire out of Lee.
On top of everything else, it was hot & muggy. Anyone who has gone camping during the heat of summer knows how hard it is to sleep even when you are exhausted. Lee had to have been sleep deprived. The combination of Davis not supporting his movement as he had planned, the anxiety brought on by lack of intel, his inability to impose his will on his subordinates & lack of sleep was compounded by another unanticipated factor.
The Army of the Potomac was fighting better than Lee had any reason to anticipate. After the first day, McClellan would have retreated, no telling what kind of blunder Burnside would have committed, Hooker could be relied upon to loose his nerve, but this time the AoP was not turning tail after the first setback. When the AoP did not pull out during the night of the second day, Lee was out of options. That must have been maddening. Nothing, absolutely nothing was working the way Lee intended it to go.
Dwight Eisenhower & Montgomery toured Gettysburg. The two of them were completely baffled by Lee's decision to attack the center of the Union line. Eisenhower said that Lee must have just been mad as hell & wanted to smash Meade no matter what. That is the same thing that Longstreet said, as well. No wonder Lee, who had a fierce temper that he had spent a lifetime learning to control, opted for the hammer & left the rest of his tools in the bag. One last smashing blow was the only thing that could salvage the situation.
The stress of his situation, the limited resources he had on hand, his belief in the superiority of Virginia soldiers, his burning anger & his belief in the inferiority of his opponent left him with no option. He went all in & drove his only fresh troops right at the center of Meade's line. If he had not, he wouldn't have been Robert E. Lee.