Here is an excerpt from my datapack code, which adjusts the CustomName every tick, based on their health.
execute if score @s mh.mobhealth matches 1 run data merge entity @s {CustomName:[{"atlas":"minecraft:gui","sprite":"hud/heart/half"}]}
execute if score @s mh.mobhealth matches 2 run data merge entity @s {CustomName:[{"atlas":"minecraft:gui","sprite":"hud/heart/full"}]}
execute if score @s mh.mobhealth matches 3 run data merge entity @s {CustomName:[{"atlas":"minecraft:gui","sprite":"hud/heart/full"},{"atlas":"minecraft:gui","sprite":"hud/heart/half"}]}
This is the world in which I reproduced the behavior. The data pack is also present and just needs to be activated.