Lincoln needed Maryland to stay in the Union so that Washington D.C. would not be surrounded on all sides by Confederate territory. If this happened, the city would soon be captured and the Confederacy would win the war. Also, if Maryland seceded, other slave states which had stayed loyal to the Union such as Delaware, Kentucky, and Missouri would secede as well.
Lincoln had problems with Maryland even before the war officially began. There was a plot to assassinate him there as he traveled through the state on the way to the inaugural. Lincoln suspended civil liberties in Maryland by jailing anyone suspected of being a secessionist. He had the Baltimore city council suspended and its mayor arrested on the grounds of being pro-Confederate. This was not a move that was initially suggested by Lincoln--his Secretary of State William Seward suggested that curtailing civil liberties in border states was necessary to keep potential troublemakers at bay. Lincoln's declarations of martial law in Maryland was fodder for dispute and it did become an issue during the 1862 mid-term elections and the 1864 presidential election, but by that time Union sentiment was starting to grow and there was a movement to win the war no matter the cost.
Lincoln prevented Maryland from seceding from the Union when the Civil War began. Lincoln understood it was essential to keep Maryland in the Union. Because Washington, D.C. was made up of land donated by Virginia and Maryland, Lincoln knew that if Maryland seceded, Washington, D.C. would be cut off from the Union. This would have happened because Virginia had already seceded. If Maryland seceded, Washington, D.C. would have been isolated. Thus, Lincoln knew he had to keep Maryland from seceding. Since the Maryland legislature would make this decision, Lincoln had to devise a plan ensuring Maryland would stay in the Union. Thus, Lincoln arrested any Maryland legislator who would have voted for secession. This prevented Maryland from seceding. This action was really illegal, but nobody in the North questioned Lincoln’s actions. Thus, by devising this plan, Lincoln was able to keep Maryland in the Union.