The bug
Ender dragon doesn't die if it's not beside the portal.
How to reproduce
Go to the end:
/execute in the_end run teleport @s 0 90 0
Give you a powerful weapon:
/give @p minecraft:stick{Enchantments:[{id:sharpness,lvl:32767},{id:looting,lvl:32767}]}
Attack the ender dragon many time before it will not working for the first time
→ ❌ You see that the ender dragon does not die and it has 0 healthWait for the ender dragon go beside the portal
→ ✔ The ender dragon dies
As far as I know, the dragon should only die if it is on top of the portal. See also MC-108901.