How can you make an armor that when you wear it, it will give you resistance 255? [duplicate]

The tag command could be used but then the item needs to be placed on the ground to apply the tag to the item, it's better to directly apply a tag to the item with the Tags:[""] parameter.

By using this command:

execute as @a if entity @s[nbt={Inventory:
[{Slot:102b,id:"minecraft:iron_chestplate",tag:
{Tags:["Immortal"],display:{Name:"{\"text\":\"Immortal Chestplate\"}"}}}]}] 
run effect give @s resistance 1 255

You will give all players that wear a chest plate named Immortal Chestplate and if the chest plate has the tag Immortal, resistance 255 for 1 sec. This will only affect any player that actually has the correct item, i.e. the name and the tag needs to match.

Place this in a command block with Repeat Unconditional Always Active.

This command will place an immortal chestplate on a player(in the chest slot):

/replaceitem entity @p armor.chest minecraft:iron_chestplate{Tags:["Immortal"],
display:{Name:"{\"text\":\"Immortal Chestplate\"}"}}

Then with the give command:

/give @p iron_chestplate{Tags:["Immortal"],display:{Name:"{\"text\":\"Immortal Chestplate\"}"}}

Using the summon command:

/summon item ~ ~ ~ {Item:{id:"minecraft:iron_chestplate",Count:1,tag:
{Tags:["Immortal"],display:{Name:"{\"text\":\"Immortal Chestplate\"}"}}}}

If you want to test for a helmet you change the number at Slot:102b to 103:b, leggings for 101b, and boots for 100b.

Note

replaceitem will be replaced with the item command in 1.17, the difference is that you need to add replace before the item:

/replaceitem entity @p armor.chest iron_chestplate{}

becomes

/item entity @p armor.chest replace iron_chestplate{}