Gandalf got them from the Mouth of Sauron who got them from Shagrat who took them from Frodo in Cirith Ungol:
As Sam entered Cirith Ungol to find Frodo, an orc ran out of the tower and:
Behind him came Shagrat, a large orc with long arms that, as he ran crouching, reached to the ground. But one arm hung limp and seemed to be bleeding; the other hugged a large black bundle.
...
[After altercations, a]way below Shagrat went leaping down the stairs and out over the court and through the gate, bearing [the bundle]. If Sam could have seen him and known the grief that his escape would bring, he might have quailed.
Shagrat -- or the bundle, anyway -- finds its way to Barad-dûr and into Sauron's hands and it is given to the Mouth of Sauron to taunt the leaders of the Host of the West:
The Messenger put these aside, and there to the wonder and dismay of all the Captains he held up first the short sword that Sam had carried, and next a grey cloak with an elven-brooch, and last the coat of mithril-mail that Frodo had worn wrapped in his tattered garments.
So, Frodo's mithril mail, Sam's sword (which he left with Frodo in Shelob's lair) and Frodo's elven-cloak and brooch arrive in Gandalf's hands via the Mouth.
The orc rags came off Frodo's back after he was rescued. In the Tower of Cirith Ungol, Frodo is naked and in order to leave, Sam dresses both of them in orc gear:
'Quick now. Mr. Frodo!' he said. 'I've had a bit of a search to find anything small enough for the likes of us. We'll have to make do. But we must hurry.
He opened the bundle. Frodo looked in disgust at the contents, but there was nothing for it: he had to put the things on, or go naked. There were long hairy breeches of some unclean beast-fell, and a tunic of dirty leather. He drew them on. Over the tunic went a coat of stout ring-mail, short for a full-sized orc, too long for Frodo and heavy. About it he clasped a belt, at which there hung a short sheath holding a broad-bladed stabbing-sword. Sam had brought several orc-helmets. One of them fitted Frodo well enough, a black cap with iron rim, and iron hoops covered with leather upon which the evil Eye was painted in red above the beaklike nose-guard.
When they finally left the road from the Black Gates to Barad-dûr, Frodo and Sam threw away most of this orc-gear, including all the military stuff, but apparently kept wearing the clothing. That clothing was still on them when Gandalf and the Eagles rescued them on the slopes of Mt. Doom and are the "orc-rags" that they wore through Mordor.