Death is the greatest penalty the court can, in its boundless wisdom, confer. The bail-sprung defendant who has killed himself, then, if guilty, has self-delivered the maximum possible penalty in his own case, by definition, plus some in all liklihood (since only the tinest proportion of cases are candidates for death), whilst saving society thousands in legal costs, and, as a bonus, has advanced the judicial queue by one place. His heirs therefore deserve back his bail money, perhaps with a proxy thank-you card.
If not-guilty, then the decedent defendant's heirs deserve back his bail money, plus punitive funds drawn against the police and prosecutorial systems, for contributing to his untimely death.
So you see, either way, it is unreasonable and immoral for the bail or bond money to be retained.