I mean, in 1862, when McClellan got Lee's army plans, didn't he know he had Lee outnumbered more than two to one so he could just have sent 40,000 men to easily take the city while the main army unit held the Southerners off? And again around the time of Gettysburg, when it was confirmed the Confederates had gone North, how didn't that leave Richmond wide open for the taking? Washington D.C. had a ring of well-equipped and manned forts anyway, so presumably they could have protected the city in the mean time. Were there leaders who said they should go take the capital while the main Southern army group was away? It's not like the Southerners were moving to threaten their supply lines.
Washington City wasn't the only strategically vital target north of the Potomac; the rail lines essential for sustaining the Army of the Potomac and Washington itself would have been left vulnerable. Baltimore, from which the only rail line into Washington runs, was almost completely undefended in 1862, as was the key rail hub and state capital at Harrisburg Pennsylvania. During both Lee's invasions, his Union counterparts made sure to protect the Baltimore-Washington railway in order to keep a stable supply situation.
Furthermore, Richmond was heavily fortified after the Peninsula Campaign in Spring 1862, and the Confederates left delaying forces to man the defenses. Even in 1864, when Grant crossed the James River to try to grab Petersburg, Beauregard held off superior assaults with second string units long enough for the main army to reinforce.
As a matter of fact, Joe Hooker actually advocated nabbing the Confederate capital while Lee's army was in the Shenandoah valley, but Lincoln told him to stay between Lee's army and Washington-Baltimore. I think he may have been right for the wrong reasons, though. He told Hooker that Lee's army, and not Richmond, was his true objective, which I would argue is a false dichotomy. Holding terrain in Virginia reduces the supplies available to the Confederates, reduces men available for conscription, and if Richmond-Petersburg fell, the whole Army of Northern Virgina would have to fall back to North Carolina, having surrendered the key rail hub and industrial center in the region.
In terms of the Maryland campaign specifically, you have to remember that after the defeats of the Seven Days and Second Bull Run, as well as the percentage of his army made up of raw, unequipped recruits, he wouldn't have enough strength to both reliably block Lee's army from nabbing Baltimore and break through Confederate defenses around Richmond. Lee would have loved the chance to destroy half McClellan's army in a concentric attack on Northern soil, and then fall upon the other half's supply lines.