There was also another factor that led towards a shift of focus: military realities. By 1863, the Union had lost hundreds of thousands of men. In July of 1863, the New York Draft Riots broke out after long lists of the dead of Gettysburg were posted next to new lists of draftees.
In other words, the Union had both a motivation and a potential manpower issue. By changing the focus of the war towards ending slavery, Lincoln won the unequivocal support of northern abolitionist churches, the abolitionist movement, and northern free blacks as well. 180,000 African-Americans joined to fight against the South, in much higher percentages than their actual portion of the population, and were some of the most highly motivated, hard fighting soldiers of the war.
Also by that time, it was getting harder to sell the idea to the American public that the war was about restoring the Union alone, as many were starting to believe it was not worth the price.
The war to save the Union became the war to end slavery mainly through Abraham Lincoln's issuing of the Emancipation Proclamation. Before that, individual Union commanders had taken steps against slavery, but those were isolated and unofficial.
When Lincoln issued the Emancipation Proclamation (it went into effect in January of 1863), the war became much more of a war against slavery. Lincoln did this because he believed that giving the war a higher purpose would be politically and militarily advisable. He believed that the Proclamation might make slaves run away from their masters (hurting the South's economy) and it might make European countries (who had banned slavery) be less sympathetic towards the South.