I have been curious about this topic in the past, and I have also wondered about modern wars as well - if there are laws against killing/attacking occupying forces. The actor would of course risk a counter-attack, but if they made it out of that, would there be investigation/prosecution if the attack was otherwise unprovoked?
An attack on soldiers by an out-of-uniform irregular combatant puts them beyond the protection of military codes applicable to civilians or prisoners of war, and subject to summary execution.
The US had instructions on civil military relations during the Civil War, the "Lieber Code" developed by the German legal scholar Franz Lieber and issued over the signature of President Lincoln in 1863 as "General Order 100".
Section 4 is "Partisans - Armed enemies not belonging to the hostile army - Scouts - Armed prowlers - War-rebels"
Art. 82.
Men, or squads of men, who commit hostilities, whether by fighting, or inroads for destruction or plunder, or by raids of any kind, without commission, without being part and portion of the organized hostile army, and without sharing continuously in the war, but who do so with intermitting returns to their homes and avocations, or with the occasional assumption of the semblance of peaceful pursuits, divesting themselves of the character or appearance of soldiers - such men . . . are not entitled to the privileges of prisoners of war, but shall be treated summarily as highway robbers or pirates.
Art. 85.
War-rebels are persons within an occupied territory who rise in arms against the occupying or conquering army, or against the authorities established by the same. If captured, they may suffer death, whether they rise singly, in small or large bands, and whether called upon to do so by their own, but expelled, government or not. They are not prisoners of war; nor are they if discovered and secured before their conspiracy has matured to an actual rising or armed violence.
So there weren't really "legal repercussions" in the sense of the existing criminal or civil law. Violators could be executed with approval of relevant military authorities-- usually a military commission, but often just an informal proceeding.
As a literary note-- Ambrose Bierce' "An Occurrence at Owl Creek Bridge" describes just such an execution of a Confederate saboteur. Bierce was a Civil War veteran, and in addition to being one of the great American short stories, he gives a good account of what he may have himself witnessed.
Many legal aspects of the Civil War became relevant again during the War on Terror-- the constitutionality of military commissions to try terrorists go back to a famous case decided by the Supreme Court in 1866, ex parte Milligan -- though this case importantly takes place after the cessation of hostilities, it gives good detail on how military commissions worked at the time.
I am not familiar with what instructions the Confederacy operated under, though they were less frequently operating in territory sympathetic to the Union.
See:
DILBECK, D. H. “‘The Genesis of This Little Tablet with My Name’: Francis Lieber and the Wartime Origins of General Orders No. 100.” Journal of the Civil War Era, vol. 5, no. 2, 2015, pp. 231–253.
Witt, John Fabian. "Lincoln's Code: The Laws of War in American History" Free Press, 2012.