Really, the South had no business fighting a battle in Pennsylvania. But a lot of what we get today is revisionist history. The most important thing we have to remember is that the historical generals did not have all of the information we have collected now in the AAR's over 150 years after that battle. They had to deal with the information they had at the time. And since J.B. Stuart was not at the battle till the afternoon of Day 2, Robert E. Lee had no idea of the positioning of the enemy army. Up until the evening of Day 2 he had thought he had caught the Union army by the seat of their pants and that their full army strength had not gathered, which was close to being true! If he had brought the fight to the Union on the evening of Day 1 or at any time during Day 2, capturing the high ground around Cemetary Ridge so they could rain down all hell upon the Union, the fight would have gone very differently.
The Confederates, more than anything else, lost the battle because they allowed the Union to control the time and location of the final battle. And if they had taken the initiative, not just in this one battle but in the war in general, they would have won the war. They had Washington DC in the palm of their hand after the first battle of Bull Run, but they didn't take it.