Just to add about the two answers, if your ID and your secret ID matches the ID and Super ID of the original owner, then you can rename it. As it is almost impossible, we refer to
"A traded Pokémon cannot be renamed unless they are returned to their
original game; if it is impossible for the traded Pokémon to be
returned, it cannot be renamed at all. If taken to a Name Rater, he
will say the name is "perfect" and refuse to change it."
~ quoted from DanH1995's answer.
I deducted this from Bulbapedia:
> As the chances of matching both the Trainer ID and Secret ID are near impossible, these nicknames cannot be changed.