Maryland was in a unique position as the United States broke into civil war. The primary divisions in the Civil War were regional, between the Northern and Southern states. These regions had considerable differences, perhaps nowhere more so than in their economy: Northern states focused on manufacturing, while Southern states relied primarily on agriculture. The main cause of the conflict between these regions leading up to the war was slavery, which was vital to the agricultural foundation of the South. The Northern states largely opposed slavery (many had abolished slavery on a state level), though this was largely on political and economic grounds rather than popular support for abolition.
Maryland was smack in the middle—a state halfway between the North and the South, which relied on both to succeed economically. It was also one of the very few slave states that did not secede during the Civil War. Due to their heavier economic reliance on and geographic proximity to the North than most Southern states, Maryland was less enthusiastic about secession than states farther south, yet they also relied on slavery to support their agricultural industry. In the presidential election of 1860, Abraham Lincoln and the Republican Party were largely seen as abolitionist (though their platform was instead opposing the further spread of slavery, rather than the elimination of existing slavery). In Maryland, Lincoln received only 2.5% of the vote, which reflects how different they were from many of the other Northern states.
Once elected, the secession movement began in earnest, and Lincoln was faced with concern over how Maryland would react—after all, the capital of Washington, DC, was just south of the Maryland border. Losing Maryland would be a huge loss to the Union and could have quickly turned the tide of the war. While Lincoln gave some early concessions to Maryland (he agreed to alter troop movements through the state to appease the local leaders who feared increasing violence from pro-secession groups), pressure from the Confederacy started to alter popular opinion within the state. Lincoln sent troops to seize the largest city of Baltimore, where martial law was declared. Habeas corpus was suspended, which meant opponents could be imprisoned without being charged with a crime—a decision that the Supreme Court found unconstitutional but which Lincoln ignored.
With Maryland in firm control by the Union military, many Confederate sympathizers were intimidated into silence (as they could be imprisoned indefinitely for essentially any reason while under martial law) or fled south.
The final act by Lincoln was the Emancipation Proclamation in January 1863, which immediately freed all slaves in the Confederate states, but crucially not in the Union slave states (Kentucky, Delaware, Missouri, and Maryland). As Maryland was still part of the Union, it further incentivized them to remain within the Union—if they seceded after the Emancipation Proclamation, all slaves would be legally and instantly freed. While the Thirteenth Amendment abolishing slavery would be passed several years later, the Emancipation Proclamation extended the institution in Maryland for those two additional years, as long as they didn’t secede.
In general, the strategic importance and unique political, social, and economic nature of the state put Maryland front and center in the Civil War. Abraham Lincoln was initially lenient with the slave state, but as tension within the state increased, he was obligated to increase troop presence and force Marylanders into acquiescence. The enactment of martial law and accompanying suspension of habeas corpus, as well as the Emancipation Proclamation, helped keep Maryland from seceding, which was a crucial element of the Union’s strategy during the war.