Obviously, it is impossible to patent common names like Bond or Potter.
So if some problem arises it is always possible to say that story character has nothing to so with that popular character.
but if story explicitly describes that it is that well known character or if writer confirms that it is indeed same character, original author will win.
Copyright laws allows fair use for parody and educational purposes.
so characters can be used for these purposes and no asking or giving any credits is necessary.
you can write spoof story "Harry potter and society of pussies"
but you cant write serious story which closely resembles original.
if we talks about original question here then using characters from other story is illegal without permission
but since nobody cares and in case of problem you can just replace names there is no need to worry.
Using same character names is legal.