When I first read James McPherson’s Battle Cry of Freedom, I came across this interesting nugget regarding the surrender of the Army of Northern Virginia:
The terms [of surrender] were generous: officers and men could go home “not to be disturbed by U.S. authority so long as they observe their paroles and the laws in force where they reside.” This clause had great significance. Serving as a model for the subsequent surrender of other Confederate armies, it guaranteed southern soldiers immunity from prosecution for treason. 
Alas, McPherson cited no source for his conclusion regarding the significance of the clause he mentions. This provided sufficient cause for me to make an on-and-off hobby, over the past few years, of running down information regarding the legal significance of the surrender at Appomattox.
My current understanding is that there isn’t any court decision [1a] on whether the terms of the Confederate surrenders effectively granted immunity to Confederate soldiers. However, Jean Edward Smith’s biography of Ulysses S. Grant does contain this interesting anecdote:
Led by the New York Times, much of the nation’s press began a crusade to try Lee for treason. Benjamin Butler…told [President Andrew] Johnson that Grant “had no authority to grant amnesty” at Appomattox, and Attorney General James Speed, acting at the President’s behest, provided a legal opinion that “the terms of capitulation were strictly military,” implying that they provided no shield against subsequent civil action. This was the context when, on June 7, 1865, a federal grand jury sitting in Norfolk indicted Lee, Johnston, Longstreet, and a host of other Confederate generals for treason. 
Upon hearing this, Lee sounded out Grant via mutual acquaintances, whereby he learned that Grant stood by the terms of Appomattox, and favored pardoning Lee. Lee then forwarded his petition for a presidential pardon to the General in Chief, who in turn forwarded it to Secretary of War Stanton with the following endorsement:
In my opinion the officers and men paroled at Appomattox C.H. and since upon the same terms given to Lee, cannot be tried for treason so long as they observe the terms of their parole. This is my understanding. Good faith as well as true policy dictates that we should observe the conditions of that convention. Bat faith on the part of the Governm’t or a construction of that convention subjecting officers to trial for treason, would produce a feeling of insecurity in the minds of all paroled officers and men. If so disposed they might even regard such an infraction of terms, by the government as an entire release from all obligation on their part.
I will state further that the terms granted by me met with the hearty approval of the President at the time, and of the country generally. The action of Judge Underwood in Norfolk has already had an injurious effect, and I would ask that he be ordered to quash all indictments found against paroled prisoners of war, and to desist from further prosecution of them.” 
However, when Stanton – who lacked Grant’s enthusiasm for Lee’s cause – failed to press the issue, Grant went directly to President Johnson. As Smith tells it:
When Grant when to the White House, he found Johnson unyielding. The President said he wanted “to make treason odious,” stating that Lee and other rebel leaders had to face punishment. Grant objected. He told Johnson he could do as he pleased “about civil rights, confiscation of property, and so on,” but the terms of Appomattox had to be honored.
“When can these men be tried,” asked Johnson.
“Never,” replied Grant. “Never, unless they violate their parole.”
Johnson persisted, demanding by what right “a military commander interferes to protect an arch-traitor from the laws.”
Grant, who rarely lost his temper, was livid. He told the president that as the responsible commander in the field he had an obligation to destroy Lee’s army. “I have made certain terms with Lee, the best and only terms. If I had told him and his army that their liberty would be invaded, that they would be open to arrest, trial, and execution for treason, Lee would never have surrendered, and we should have lost many lives in destroying him. My terms of surrender were according to military law, and so long as General Lee observes his parole, I will never consent to his arrest. I will resign the command of the army rather than execute any order to arrest Lee or any of his commanders so long as they obey the law.”
Andrew Johnson was a stubborn man, but he knew when he was overmatched. He realized that without Grant’s support his administration would be in serious trouble. He did not doubt Grant meant what he said, and so he backed down. On June 20 Attorney General Speed instructed the United States attorney in Norfolk to drop the proceedings. Grant then wrote to Lee, enclosed a copy of his endorsement of Lee’s request for clemency, and without mentioning his discussion with Johnson, said simply that the government had accepted his interpretation. […]  [Emphasis in original]
So it appears this particular legal question was never actually adjudicated. At least not in the courts of the United States. Instead, it was decided by the President…mainly on the strength of an amicus curiae brief filed by Gen. U.S. Grant.
As for Lee’s pardon…that is a story with two parts.
The pardon petition submitted by Lee (and endorsed by Grant) was never acted upon. Initially, this was because the petition failed to include the oath of allegiance required under Johnson’s initial amnesty proclamation . However, when Lee attempted to correct this oversight a few months later, the notarized oath he submitted got misfiled by the State Department. Meanwhile, Secretary of State William Seward apparently gave Lee’s pardon petition to a friend as a souvenir . As a result of such incompetence, Lee never received a specific pardon during his lifetime. However, as noted by the War Department in 1936 (HT Bob Huddleston), the terms of President Johnson’s on Dec. 25, 1868 amnesty proclamation were broad enough to encompass Lee .
Even after being pardoned, however, Lee remained subject to the political disabilities imposed by the Fourteenth Amendment, until his death in 1870. An Act of Congress  rescinding such disabilities was passed in 1898, but since that law “was not intended to have any posthumous effect” , posthumous restoration of Lee’s full rights of citizenship required an additional Joint Resolution (passed over a century after Lee’s death, in 1975) .
 James McPherson, Battle Cry of Freedom, at 849 (1988).
[1a] Then again, the June 8, 1865 issue of Philadelphia Inquirer apparently carried the following excerpt from Judge Underwood’s charge to the Norfolk grand jury.
To the inquiry which has been made by an officer of the Court, whether the terms of the parole agreed upon with General Lee were any protection to those taking the parole, the answer is, that was a mere military arrangement, and can have no influence upon civil rights or the status of the persons interested.
Simon, infra note 3, at 150. It’s not clear to me whether or not this charge could serve as legal precedent of a sort. One of these days, I’ll try & run down a copy of the court records from this case (along with Attorney General Speed’s opinion on the matter).
 Jean Edward Smith, Grant, at 417 (2001). Aside: I see the rule of law had friends back then, as well as now….
 John Y. Simon, ed., 15 Papers of Ulysses S. Grant, at 149.
 Smith, supra note 2, at 418.
 Proclamation of May 29, 1865, 13 Stat. 758
 Elmer Otis Parker, “Why Was Lee Not Pardoned?” Prologue, Vol. 2, No. 3 (Winter 1970), p. 181.
 Proclamation of Dec. 25, 1868, 15 Stat. 711
 Act of June 6, 1898, 30 Stat. 432, Ch. 389
 H.R. Rep. No. 94-324, at 6 (1975).
 Act of August 5, 1975, 89 Stat. 380.