At Gettysburg, the Provost Guard of the Army (under General Marsena Patrick) took control of the Confederate prisoners soon after they were captured. They were gathered together and guarded the night following their capture, and at daylight were lined up in a column of two ranks and marched south 25 miles to the closest available railroad line at Westminster, Maryland, where they were transported by rail to locations such as Baltimore, from where they again marched to the prison camps. Wounded Confederates were eventually sent to hospitals in the far North and, once recovered, were then escorted to the prison camps, so that new batches of prisoners arrived daily in the camps over several weeks. Officers were separated from enlisted men because the former were destined for incarceration at Johnson's Island, Ohio.
Here is a first-hand account:
(War Reminiscences, Corporal John W. Stevens, 5th Texas) - On the morning of July 3 [1863] we (about 500) started for Westminster, under a guard of the 5th New York Cavalry; our commander was a captain, a "soldier," a gentleman, and was kind to us as he could be. He conducted the march in army regulation style, march 50 minutes and rest 10. A commissary sergeant of a supply train began to taunt us, when the captain rode up. He said, "You shut up and let these men alone; they are prisoners of war, unarmed and under guard, and you shan't insult or tantalize them; and if you don't think they can or will fight, d--n you, get a gun and go front yonder and you'll find all the fighting you want to do, and doubtless a little more." Then came our time: we yelled and guyed him to our hearts content, much to the amusement of our captain. ... We were formed in two ranks. The tallest men were put first at the head of the column. This arrangement put this writer as No. 1, and my file mate was Lt. Col. B. F. Luce of the 18th Mississippi. I then measured six feet and two inches, weighing 222 pounds, was 31 years old. About the middle of the evening we reached our point of destination, which was the base of their supplies. ... As night closed down we were placed in some box cars, where we remained until daylight, when an engine was hitched on and we were run into Baltimore, arriving there about 8 or 9 a.m. on July 5. Marched to Fort McHenry, arrived about noon.