Lincoln didn't declare war. You declare war on another country and the confederacy was a group of states in rebellion, nothing more and nothing less. Congress gave the president the power to mobilize the militia to put down invasion or rebellion when Congress was not in session. Lincoln's actions were perfectly legal.
To be more precise they were a group of Sovereign States in the legal process of leaving the Union.