Details: Even though the Cosmog you befriended along your journey ended up becoming the Cover Legendary Pokemon, Solgaleo, you can still obtain another one in game so you can add it and its secondary evolution to your Pokedex. However, the way of obtaining it is quite complex.
First things first: You must first defeat the Elite Four and the main storyline of the game. By doing this, it will turn to night in Pokemon Sun. After such occurrence, you can return to the Altar of the Sunne with Solgaleo in your party and go back to the other world, where it will then be night in you game.
From there, still with Solgaleo in your party, go to the Lake of Sunne off Ula'ula Meadow, all the way up to the lonely altar. Cosmog will soon appear, only at Level 5 with the move Splash, and it will want to join your party. You won't have to Battle it; it will want to join you and your gang automatically.
This Cosmog will eventually evolve into Cosmoem at Level 43. The Cosmoem it evolves into will later evolve into another Solgaleo.