During the American Civil War, the major disadvantage that the South had to the North was their lack of food growing farms, because basically the entire region was dedicated to producing cotton. So, why is it that when the South invaded the North, they pushed northwards into Maryland and Pennsylvania instead of trying to capture the corn and wheat producing states in the Midwest?
To start I will disagree with your statement, the idea of lack of food is wrongly interpreted. The South had food in abundance, even for the troops, their main issue was the lack of a proper railway system (or any others) to move those supplies around and particularly to get them to its armies in the field. Worth noticing that the existing railway network in the Confederacy remained in private hands throughout the war, as opposed to the Union one controlled by the War Department, and often private & business interests prevailed over military priorities. Now, putting this in perspective you will see other reasons for invading the North, particularly in the Eastern theater. Once Lee became the commander of the Army of Northern Virginia, the main military force of the Confederacy in the East, it became quite clear for him that he had to push the Federal troops as far from Richmond as possible, otherwise he would permanently faced the issue of being thrown into the city defenses and face a siege that he would eventually loose as it happened in 1865 around Petersburg. In addition Davis and Lee had political and strategical reasons of their own to invade the North. On one hand it was expected that once Confederacy troops got into the border states such as Pennsylvania that would encourage the Confederacy sympathizers to raise and speak potentially tilting the state into joining the Confederacy. It was also seen as viable that another Union defeat in its own controlled territory (do not forget that Lee managed to beat the Union Army of the Potomac over and over up to Gettysburg in 1863) would make the European powers, mainly England and France, to openly take sides in the war and recognize the Confederacy as it could defend itself and the Union was not strong enough to win, they were very close to achieve this. More linked to your question is the question of supplies. Lee openly admitted that invading the North, in 1863 in this case, would give a break to the Virginia farmers whose soil was barren by war and desperately needed a crop. You must imagine the presence of an army of 50,000 plus in your area extending for miles and camped in need of constant supplies. Everything that is within reach of the Army will simply disappear, livestock and hens and pigs to feed the soldiers, any bread, corn, potatoes etc for the same purpose, not to mention hams, flour, sugar, salt etc. Fences will be cut down to make fire in the camps and horses will be taken to pull the artillery wagons, the supply train and for the cavalry. Whether done paying for it or stolen you can speculate but the fact is that all will go despite any provost effort, armies need to be fed to keep them in the field. Imagine the Virginia counties after 3 years of war with both Confederacy and Union armies camping and fighting around, 100,000+ men not counting camp followers. It must have been a desolated area. While the Union had a good supply system the Confederacy constantly struggle to move supplies to the front either by its limited railway assets or by mule and cart in supply trains several miles long. That picture of shortage was true in the front and became and issue in some cities like Richmond when the Union blockade tighten more and more and limited imports could be brought in by sea. Inflation became rampant too. By contrast as late as 1865 North Carolina claimed that had thousands of bushes to feed the army horses, but the army had no means to get them across to Virginia for the few remaining horses. During Sherman's march to the sea he decided to cut off with his line of supplies and live off the ground; sent forage parties covering as much as 15 miles around him while advancing and recorded in his memoirs how surprised he was with the quantity of supplies obtained, he was crossing Georgia and no shortage. Hope it helps a bit.
If you look at a map of railroads, you can see that the Baltimore and Ohio RR was pretty unreliable since it ran through areas that changed hands several times during the war. The Pennsylvania Railroad was therefore the main route to bring the agricultural produce of the Midwest into the eastern theater for the war.
Most of the supplies from the west were staged in Harrisburg before being sent south, which explains why Lee made the city his primary target when invading Pennsylvania. The Confederates would be well supplied and would have severed the major communication link with the western states. Quite similar to what Grant was able to accomplish at this point in time by taking Vicksburg.