united-states
It would not be a defense to the charge. But, it wouldn't be irrelevant either.
Prosecutors exercise discretion when deciding whether or not to press criminal charges, and in considering what kind of plea bargains to offer. A good outcome for the crime victim, or voluntary efforts of the perpetrator to remedy the harm done in the crime, can influence how a prosecutor exercises that discretion.
If the victim doesn't feel very aggrieved, the victim could also ask the prosecutor not to press charges, although the prosecutor wouldn't be required to honor that request.
Also, while guilt or innocence at trial is a binary decision that is usually made by the jury in the U.S. (although sometimes it is made by a judge in bench trial) according to inflexible jury instructions, there is a great deal of judicial discretion in making a sentencing decision after there is a conviction (if there is a conviction).
The amount of harm that the victim has suffered, and the attitude of the convicted defendant, are two important factors in how sentencing discretion is exercised.
In federal criminal cases, this sentencing discretion is codified in the United States Sentencing Guidelines which consider the dollar amount of the loss from the theft, and acceptance of responsibility, which together with the charge of conviction and the criminal record of the defendant, are used to generate a presumptive sentencing range, which the judge may then honor, or may deviate from for reasons described by the general portions of the federal criminal code.
In most state and local courts, the judge has much more sentencing discretion, with a range of options established by the offense of conviction and any aggravating factors (like prior criminal convictions) set forth by law.
If the harm suffered by the victim was modest, and especially, if the defendant tried to make things right after committing the crime in a way that causes the harm to the victim to be modest, this would often lead a judge to impose probation where a sentence of incarceration would be another sentencing option, and to impose smaller fines or short sentences of incarceration, if these are imposed.
While a scenario like the one in the question where an unexpected windfall event causes the harm caused by the crime to be much less than would ordinarily be the case, this also makes the crime less serious in many cases.
For example, the maximum statutorily allowed sentence for theft often depends upon the dollar value of the loss suffered (although more often, it depends upon the dollar value of the property stolen), and a lower value could make the difference between petty theft and grand theft, which would be the difference between a felony and a misdemeanor.
But even though the dollar value of the property stolen might be the statutory measure of the severity of a theft crime, if the vehicle was returned undamaged not long after the theft and the actual loss was only, say $300, rather than the $30,000 of loss that would have been experienced if the car was never recovered, the prosecutor might very well accept a plea bargain down to petty theft, especially if the vehicle was voluntarily returned undamaged before the defendant was caught.
Also, as another answer has noted, theft is taking property with an intent to permanently deprive the owner of it. If a vehicle were taken during a natural disaster with an intent to reach a point of safety from the disaster and then to promptly return the vehicle to the owner, that wouldn't be theft of a motor vehicle. It might be a lesser offense (like joy riding), or it might be no crime at all (if the offense could be justified as an action reasonably necessary to save one's own life or the lives of others).
A real life example of this is the case of Jabbar Gibson who stole a bus to help rescue dozens of people who were in grave risk of harm from Hurricane Katrina and drove them to safety. Rather than being prosecuted, he was hailed as a hero.