Even though the Cosmog you befriended along your journey ended up becoming 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. In order to find it, 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 Reverse World, where it will then be day once again in your 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, being 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; Cosmoem will later evolve into another Solgaleo.