Slavery was only made an issue when the north's back was to the wall....it was a desperate ploy...
Slavery was an issue because the South's political leadership made it about slavery. You see it in the secession ordinances and you see it in the military decisions made by the political leaders of the Confederacy. Patrick Cleburne argued for mass use of slaves as soldiers in exchange for their freedom:
Patrick Cleburne's Proposal to Arm Slaves
Here is a quote from that letter from January 1864:
It is said slavery is all we are fighting for, and if we give it up we give up all. Even if this were true, which we deny, slavery is not all our enemies are fighting for. It is merely the pretense to establish sectional superiority and a more centralized form of government, and to deprive us of our rights and liberties. We have now briefly proposed a plan which we believe will save our country. It may be imperfect, but in all human probability it would give us our independence. No objection ought to outweigh it which is not weightier than independence. If it is worthy of being put in practice it ought to be mooted quickly before the people, and urged earnestly by every man who believes in its efficacy. Negroes will require much training; training will require much time, and there is danger that this concession to common sense may come too late.
The politicians who reviewed this letter rejected the proposition. If it had truly been about Northern "aggression," if it had truly been about obtaining liberty from tyrannical rule, then the CSA leadership would have moved heaven and earth to secure freedom even if that meant weakening the institution of slavery to do it.
The problem was that slavery was too important to the political leaders of the CSA to sacrifice for the sake of independence. It was their reason for secession...and it would take a moment of absolute despair before they finally gave in to Cleburne's idea at the closing stage of the war. Too little and too late.
Interesting to note that Cleburne serves in the Western Theater of the Civil War. He is one of a handful of major Confederate officers who comes out of that theater with any credit. You say Lincoln pushed forth the Emancipation Proclamation because he was losing. Problem with that assumption is that it completely ignores what is going on in the West at that time. Grant, Sherman, and even Rosecrans were advancing and taking control of territory. In the Deep South, Farragut took control of New Orleans.
Lee and the Army of Northern Virginia were having a good run where the population existed and the media focused the attention. But they were largely a defending force, failing to make any lasting impression on American supply and transportation lines.
Out West, the CSA was getting stomped. That rout had a massive impact on Lee's ability to feed and cloth his Army properly. Winfield Scott's strategy was working.
Lincoln issues the Emancipation Proclamation after the "victory" at Antietam to deny his political opposition the chance to accuse him of desperation. Note that he didn't need a comprehensive victory; all he required was his eastern force to hold the field after a major battle. He issues it primarily to put pressure on the South at a point where it is at its weakest. He also issues it to make certain the United Kingdom will not form an alliance with the rebels. That almost happened...and such an event would have led to a CSA victory.
Once the United States decides to turn it into a war to free the slaves in the South, a Great Britain heavily-influenced by the ideals espoused by Wilberforce and other abolitionists will stay on the sidelines and watch it play out even as their ports in Liverpool and Bristol suffer economically.