Porygon2 and Porygon-Z are available in Pokemon Sword and Shield's first DLC pack the Isle of Armor.
If you want to know how to get them both, keep reading.
Upgrade/Dubious Disc
To evolve Porygon into Porygon2 you must trade it whilst holding an Upgrade.
Upgrades could previously be obtainable by spinning Pokestops or Gyms or by opening a Gift.
You can get a Porygon-Z by trading a Porygon2 whilst holding a Dubious Disc.