From a Confederate viewpoint, Peyton Farquar--the protagonist of Ambrose Bierce's unforgettable short story, "An Occurrence at Owl Creek Bridge"--is a hero. From a Union point of view, he is nothing but a cowardly spy. As a spy caught in civilian clothing, a hanging was his due reward; it was probably considered illegal according to both Union civilian and military laws, though spying has been a widely used practice for centuries. As a native Alabaman and Confederate sympathizer, Farquar probably considered it his duty to take this action, though the story notes that he would have preferred the more visible glories of the battlefield. But sympathetic eyes were needed behind enemy lines, so Farquar chose this method to serve the Confederacy. Like the famed American Revolutionary War spy Nathan Hale, who was immortalized for giving his one life for his country, Farquar was both a hero to his new nation and an illegal participant in the eyes of his enemy.
What is it that Peyton Farquhar has done illegally? Be a part of the secession of the South? The answer to this question depends upon one's interpretation of the Constitution that invokes the "right of revolution" if the government becomes too oppressive or acts against the common interests.
In their fight for states' rights, the South felt justified in their secession from the United States. However, Abraham Lincoln did not perceive the secession justified and sent troops to assure that the Union was preserved. So, if the reader takes the perspective of the South, Farquhar is a hero, a man who risks his life for the rights of his countrymen. On the other hand, if the reader sympathizes with the North, Farquhar has acted illegally by tampering with the Owl Creek Bridge.
Of course, since the narrative explores the inner workings of the mind of the character who has committed the act of sabotaging the bridge, the sympathetic reader will perceive Farquhar as a hero rather than feel his life a senseless waste.
I do not think that your questions are really an either-or type of a thing. It is what we academics call a "false dichotomy." That means that you are saying that two things are opposed to one another when they are not.
The answer to both of your questions is "yes." He is a hero and he is acting illegally. If he is on your side of the war, he is a hero, but he is still acting illegally.
People who try to do sabotage or espionage out of military uniform are doing something illegal. But when they are on our side, we love them -- Nathan Hale is just such a hero.
So Farqhar is a hero for trying to help his "country." But he was acting illegally when he did it.