The Starkiller Base was targeting the Resistance base wasn’t it?
If so then why did they need to lightspeed it back and if the sun was destroyed why was it light at the end when they came back? Was I missing something?
Because the StarKiller wasn't in the same system as the Resistance base. The weapon's range is demonstrated earlier in the movie, it's exact range is unknown but it seems to be incredible.
The first part of your question asks:
The Starkiller Base was targeting the Resistance base wasn’t it? If so then why did they need to lightspeed it back…
Unlike the Death Star from the first Star Wars film and even Death Star II in Return of the Jedi, Starkiller Base did not have to be as close to it’s target. Remember the Death Star needed to orbit around Yavin to be in range of one of Yavin’s moons—Yavin 4—where the Rebels were hiding.
In contrast Starkiller Base can not only destroy multiple planets are once, but can also do so at a great distance from another star system. Where the delay in the Death Star attacking was mainly connected to getting in orbit near it’s target and then charging it’s weapon to fire, Starkiller base’s main impediment to attack was charing it’s weapon by draining power of a nearby star/sun and then firing it.
With that understood, addressing this aspect of your question:
…and if the sun was destroyed why was it light at the end when they came back? Was I missing something?
This is based on what I visually saw in the film: Since the main power source for Starkiller Base was literally sucking the energy away from a nearby star/sun, when the Resistance attacked the base they did not really explode the planet as much as released all of that captured power from the sun/star and the planet was consumed by it in a fireball.
Whether the planet then stabilized into a sun/star itself is unclear based on what we know, but at least up until the moment the Resistance warped back to their base on the planet D'Qar, it seemed as if it the planet itself didn’t become a new star/sun it at least was so consumed by fire for enough time it seemed to be a new star/sun.