As your wording correctly indicates, Lincoln initially did not wish to interfere with slavery in the states where it already existed. Though he was explicitly opposed to the institution, he believed that immediate abolition would simply create too much disorder in the southern states. By excluding it from the territories—the areas of the U.S. that had not yet been organized into states—Lincoln believed that slavery would eventually die a natural death. His intention at the start was to attempt ending the rebellion quickly and to bring the seceded states back into the Union with as little disruption as possible to southern society.
Obviously this didn't happen. As early as First Bull Run (Manassas) in July of 1861, with the rout of Union forces and their headlong retreat to Washington, it became clear that the rebellion couldn't be put down quickly and with little bloodshed. Over the next year each development confirmed that the war would be long and protracted. Though Union progress was being made in the western theater (despite huge casualties at Shiloh in April, '62), in the east this wasn't the case. Union defeats, with thousands of dead and wounded on both sides, occurred in the Seven Days' battles outside Richmond in June and July of 1862 and at Second Bull Run in August. Lincoln and his administration realized a fundamental change had to be made in the actual goals of the war if the Union was to be successful. The emancipation of the enslaved people was to be the cornerstone of this new objective.
It's cynical, and simply false as well, to view this change entirely as a desperate measure Lincoln carried out because the war was going badly. This was part of his motivation, admittedly, but Lincoln's understanding of the issues was evolving independently of events on the battlefields. As a result of study, of introspection, and of the persistent lobbying efforts of abolitionists such as Frederick Douglass and others, Lincoln's intentions were gradually transformed. In addition, the enslaved people had also effectively begun liberating themselves, fleeing by the thousands across the Union lines. Southern society already had been disrupted, and massively so. In order to forestall the criticism (which was leveled at him anyway by the South and its apologists, and still is in some quarters today) that he was doing so merely because he was losing the war, Lincoln waited until after the quasi-victory of Antietam in September, 1862 to issue his preliminary emancipation measure. When it was officially proclaimed in January, emancipation (though at this point unfortunately only in the areas "in rebellion") accomplished the following things immediately:
1) African American men could now be recruited in large numbers into the Union armed forces and thus aid the cause of liberation.
2) It made recognition of the Confederacy by the European countries that had previously been sympathetic to it, Britain and France, impossible. Now that abolition was an explicit goal of the war, it would have been an embarrassment to those countries, with their humanitarian pretensions, to be enemies of the side that sought to end slavery.
3) There was now no longer a disconnect between Lincoln's philosophy, which had always been anti-slavery, and the manner in which the war was to be prosecuted.
When the new nation "conceived in liberty" had been founded "four score and seven" years earlier, slavery had been a blot on its ideals and its very existence. The Founders who declared independence, including those like Jefferson who were practitioners of it, knew that slavery was wrong. They failed to enact abolition in 1776 (though the northern states did pass gradual emancipation laws in the wake of the Revolution) for the same reason that Lincoln wanted to avoid it 85 years later, in 1861: the assumption that it would create chaos. Lincoln finally took the decisive step to remove this stain from the United States—partly because it was necessary for military and diplomatic reasons, and partly because the step was in accordance with the principle of freedom for all in which he already believed, but so far had failed to act on.