A trade machine is used to trade Pokémon with other players. It has no real use in singleplayer.
Trade machines can be obtained by crafting them. A pickaxe is required to retrieve them once they are placed. When crafted, there is a small chance that you will receive one of Porygon's constituent parts, used to create the Porygon item.
It is possible to use dye on a trade machine to change its color. This cannot be done via the crafting interface; the trade machine must first be placed. Only the player who placed a trade machine may dye it. After dyeing a trade machine, breaking it will still return the default red trade machine as an item.
Trivia
Before Reforged came out, trade holder side parts had different recipes. These recipes no longer work.