Say the Confederates win the third day of the battle. Why does the war end?
The best scenario for this to happen is if Meade is forced to Surrender. If Meade surrenders then Lee's Army can take Washington, Baltimore and even Philly because their isn't a strong enough contingent of troops that can resist the whole of Lee's army.
How exactly is this supposed fantasy of a surrender by Meade going to happen?.
Lee is in no condition to besiege Meade and the Civil War was one in which the defense had superiority. At no point was Lee ever close to crushing the Army of the Potomac. While it is conceivable for Lee to have forced Meade to temporarily leave the vicinity of Gettysburg, he's still left with no viable option other than to do as he did after Sharpsburg and return home.
Moreover the defenses around Washington garrisoned by the XXII Corps were sufficient to keep Lee out of the Capital. Lincoln may have worried overmuch about the defense of Washington City, but not without reason. While the XXII Corps certainly could not have taken the field against Lee, they didn't have to. They only had to hold their own and were sufficient to that task.
Lee did about as well as could be expected in his 1863 campaign. One way he could have done better would've been if the Army of the Potomac had dashed itself to pieces against a dug-in Army of Northern Virginia which I can't see a survivor of Fredericksburg such as Meade, or even Hooker, attempting.
The other would have been for Lee to keep the Army of Northern Virginia largely intact and conceded Gettysburg after the second day.