I traded a cosmog from sun to ultrasun and leveled it up from 1 to 53 and got a solgoleo I ALREADY have a solgoleo
Cosmog evolves into Lunala or Solgaleo depending on the version it’s in at this moment (Lunala in (Ultra) Moon and Solgaleo in (Ultra) Sun)
Trading Cosmog is actually what makes it unique. If you want Lunala you can simply trade it over to a copy of Moon/Ultra Moon and evolve it. If you want a Solgaleo you can alternatively trade it to Sun/Ultra Sun and evolve it. It doesn't matter what game the Cosmog originally came from that determines which legendary it evolves into, only the version it is on when it evolves. This can be especially useful if you want to fuse Necrozma with the other main game legendary but don't have the other game (since you can just trade your Cosmog to a friend who has the other version to evolve it).