tl;dr Modern industrial warfare pushes the economy to 100% utilization; this cures the effect of an economic downturn (which is effectively suboptimal economic utilization).
Wars in general, and the civil war in particular create stimulus spending - governments buy bullets and boots. Governments drive the economy to 100% utilization. Unemployment vanishes as young men move from their traditional jobs to new jobs created just for the war. As @jwenting points out, mortality decreases the size of the labor pool, which affects the economic power of the remaining labor pool. Individuals not normally in the labor pool take up jobs to replace the young men.
Industry is pushed to 100% capacity - industry produces war goods on a priority footing, causing shortages of consumer goods, which drives up prices, drawing even more idle resources (e.g. labor, capital) into production.
Between government need for new weapons and technologies, and the retooling of production lines to produce more bullets and less butter, there are opportunities for innovation. Innovation makes more efficient uses of the available resources and deepens the capital pool dramatically. Furthermore, during wartime, innovation is easier. In normal conditions there are always opponents to innovation, because innovation is never Pareto Efficient. War lowers the commitment to Pareto Efficiency and makes innovation easier to implement. A full explanation of this phenomenon would probably require a small essay.
Wars act on financial markets - because wars are intrinsically an existential threat to governments, they borrow money heavily, which further increases the size of the economy and draws financial assets into the markets. There are additional effects of 100% utilization on capital markets, but I would need a lot more caffeine before I could address that question.
The civil war was arguably the first industrial war - although the war was fought with boots & bullets, the war was won with trains and industrial production. The North ultimately won because it could outproduce the South.
For sources, consult any book on macroeconomics, search on Keynes or Helicopter Ben Bernanke; you can also draw an analogy to quantitative easing.
It may also be useful to consult the Parable of the Broken Window; many people believe that the economy grows as the participants replace things that were broken. This is a fallacy. (I might argue edge cases of the fallacy, because there is some benefit from the increased efficiency of new infrastructure & the cost of brownfield vs greenfield development, but those are edge cases and would require a much longer essay. (and I'm probably not competent to write it; I'm only a hobby economist)).
A full answer to the question would address the cause of the 1857 panic; unfortunately the 1857 panic was caused by shortfalls in the specie market and it is commonly known that I cannot discuss specie based currency without entering a irrational raging madness that causes me to froth at the mouth like a rabid dog and post page after page of furious invective of the quality usually found on conspiracy web sites. Today I've chosen to spare us that spectacle.
@jeff asks whether the results would have been different with fiat currency vs commodity (specie) currency. Not really; the chief difference is that fiat money facilitates a monetary policy, where commodity money restricts the ability of the government to employ a monetary policy. In either case war is an existential threat, (If the government doesn't address the war, the government ceases to exist). In either case, the government must shift the economy to a wartime footing, and in doing so demand more from the labor and capital markets. That increase government demand is what recovers the economy from the downturn. The mechanics are slightly different, but the effect is the same.
Wars may cause famines, and the government may choose to address those famines; if the government does, it will continue to stimulate the economy, but the ability of the government to make such choices are constrained by the deficit spending to fund the war. But now we're well outside the scope of OP's question.