When you take enough damage in a space battle your components will stop working. So if your guns get damaged you cant shoot, or if your engines get damaged you can't move, etc. When this happens a red eject button comes up and you can click it. This will cue and animation of your ship exploding and after that you appear back at the space station in your ship.
You can then communicate with the space station and choose to land or repair your ship. There will be several different options for repair, from a little repairs to complete repairs although some stations won't fully repair your ship. It costs a few hundred credits for repairs, probably less than buying repair kits from a shipwright and repairing it yourself on the ground.
If you get destroyed enough times, your components will loose condition and need to be replaced. I always upgraded to better components before this happened though.