In the province Skåne -- formerly a Danish province -- they used to give the children the same names that their DEAD ancestors -- at the time of the birth (baptism?) of the child -- had had. They started looking for dead ancestors of the right sex as close as possible, starting on the fathers side.
Sometimes this meant that two LIVING children had the same name! (There is even at least one example of THREE living children!) One of my ancestors got twins, and both were named Måns -- one after his paternal grandfather, and one after his maternal grandfather.
If a child died, many times they gave the child of the right sex the very same name, just as you mention. But I'm not certain if they 1) named the new child after the now dead child, or 2) if they named the new child after the same ancestor that the now dead cild had been named after, thus ascertaining to have a LIVING child named after that very ancestor. (I guess I'll never know!)
Many hold the view that this is a remnant of the heathen belief that the soul kept on living after the body had died (ignoring the fact that the soul IS the person), and hence they needed to give the name of the dead person to a new person.
Regards, Mikael!