You can get one and only one Cosmog.
After becoming Champion, go to the Alter of the Sunne/Alter of the Moone with Solgaleo (daytime) or Lunala (nighttime). The opposite for Pokémon Moon — Solgaleo in the nighttime or Lunala in the daytime.
An Ultra Wormhole will open up. Go through it and you'll end up in a parallel world with the opposite time of the normal world (so, nighttime when it should be daytime and vice versa). If you go to the Lake of the Sunne (Sun) or Lake of the Moone (Moon), and have Solgaleo/Lunala in your party, Cosmog will appear. It will join your party automatically.
You can't get another Cosmog.
Source 1
Source 2
Source 3
Source 4
Also remember that Cosmog will still evolve into Solgaleo in Pokémon Sun and Lunala in Pokémon Moon.