The remaining fuel gets unloaded to the planet when you scrap a ship, and it will even directly message you to say how much you got from it.
To unload fuel without scrapping, you will have to head to the design window with the ship design in question and check the "tanker" checkbox. This allows all the fuel unload/load and sharing commands when giving orders in the task group window, but it is generally good to not leave that checkbox eternally checked later, as it designates the ship as a tanker in any regards, meaning thirsty ship will probably try to refuel from it, and that could have unwelcome effects.