I can say with fair confidence that if an astronaut died on a short mission to the moon, the craft would turn around and come back. But it gets thornier if the astronauts are on Mars, or even halfway there—any place where turning back would be inadvisable or even impossible.
There are really only two options for the body: Leave it there or bring it home.

My guess is that NASA would make every effort to bring the body home. Returning the body would most likely be incredibly important for the other crewmembers, who would have formed an extremely strong bond with one another during the three-year mission (and although the astronauts chosen for this mission would have such a demeanor that they would be less likely to freak out about sharing the ride home with a dead body, they may need to undergo grief counseling en route). In addition, when a person dies, his or her body becomes the property of the next of kin, who would have the legal right to ask to have the body returned. NASA would certainly take such a request into consideration.

The cause of death could be a huge factor in the decision. If the astronaut died from falling into a canyon, retrieving the body could put other crewmembers at risk. There’s also the extremely remote chance that the astronaut’s suit could suffer a breach and he or she could become infected with a deadly organism that could endanger the rest of the crew—and Earth. There is no evidence that any such organism (or any organism at all) exists on Mars, but there still needs to be a plan in place for this scenario. Without a way to contain its spread, we’d have to leave the body behind. But this in turn raises concerns about contaminating Mars.

Paul Root Wolpe is a psychiatry professor at the University of Pennsylvania and a bioethics adviser for NASA. His opinions on future scenarios are not the official stance of the space agency.