When you change the name of the item in the anvil and place it and then destroy it, the name goes back to the default
Related issues
Comments

To add on, I noticed in the environment field of this report that you mentioned this issue occurred whilst playing with Optifine and this modification isn't support by Mojang. just to inform you, the bug tracker only handles problems that are in Vanilla Minecraft, (unmodified game versions). Since this issue can be reproduced in a vanilla atmosphere, it will be marked as a duplicate of MC-209.
Duplicate of MC-209