When a patron dies, one shouldn't simply remove the patron from the database, in order to keep track of the patron's past circulation history. However, setting the expiration date to the patron's death date doesn't prevent the system from increasing the patron's age (indefinitely, as time passes), which is then displayed in the patron's details. I would then suggest to introduce some "death_date" additional field to the patrons table, and modify moremember.pl to compute the final age using death_date rather than the current (today's) date, whenever death_date is nonempty.
I wonder about this in terms of data privacy and GDPR, I'd say we should delete this data once all outstanding checkouts/fines have been taken care of. And I am not sure if we should encourage libraries to keep this kind of data by adding a specified field. It sounds like you would like to freeze the age, so a patron attribute would not quite work for you. Would be interesting to get some more input here.
How about then computing the patron's age until the patron's expiration date, if nonempty? This wouldn't require adding any field (and associate it to any specific event, such as the patron's death), but would prevent the system showing ages in principle increasing indefinitely.
Let's take a step back: why is the computing of the age important? I don't think we should stop for expired accounts, it's still a good information in most use cases. And expiration and age are not really linked in any way.
I think that originally the reason why the age of a patron should be displayed was to help the librarian to identify the patron as an adult or otherwise, and therefore to conclude whether restrictions should be applied.
I assume you wouldn't keep the data of deceased patrons very long. Also you wouldn't want to check out any new items, so circulation rules would be irrelevant. What I would probably do is to create a restriction of type "DECEASED" and set that. That would restrict the account and at the same time make it clear what happened. It would also be easily possible to use that in reports and the like.
Technically speaking, if the patron is deleted, they'd still be in the deletedborrowers table, so you could delete patrons who have died and just write SQL reports to show any relevant information. Giuseppe, is this a hypothetical issue or is this coming from an existing library? I didn't notice a Koha on the Internet for your organisation.
I was just looking at the function for getting age for unrelated reasons, so this is on my mind a bit. Looking at the patron details in the staff interface in English, it doesn't technically say the age of the patron. It just notes how many years ago they were born. It's not uncommon to celebrate the birthdays of famous people many years after their deaths, so I don't think there is an issue with the year displayed continuing to increment. For display purposes, if an attribute of DECEASED were added, you could also use Javascript to dynamically update the display accordingly.