It is an Ashkenazi folk custom to change a person's name when is gravely ill or in danger of death, with the idea that maybe the Moloch Ha Mavet (the Angel of Death, illustrated above by Mengele) may be tricked. Some say that a name cannot be changed by ordinary people, but only by someone of special qualities. But this is only to change the first and principal name. But if a name is merely being added, anyone can do it.
Some have the custom when changing the person's name to open a Chumash (the Pentateuch); the person then is given the first name of our ancestors that appears on the right hand side of the volume. But if the name that appears is the name of a rasha (an evildoer), the peson is not given the name. Others say that it not proper to open a Chumash as a means of casting lots. When changing a name, the added name becomes the first name.
A sinner who repents should have his name changed.