If you change minecraft:generic.max_health using /attribute command, it doesn't update your current HP.
This is not a big problem for increasing health, since it will regenerate. However, if you lower your health, it stays the same until updating it via taking damage - it will then lower it to current max value, no matter how strong the hit was.
How to reproduce:
Regenerate to full 20 HP.
Use /scoreboard objectives add hp health and /scoreboard objectives setdisplay sidebar hp to see a scoreboard displaying true health.
Use /attribute @s minecraft:generic.max_health base set 10.
Notice how your HP stays the same - 20.
Take damage. Notice how HP changes to 10.
Thank you for your report!
We're tracking this issue in MC-180001, so this ticket is being resolved and linked as a duplicate.
If you would like to add a vote and any extra information to the main ticket it would be appreciated.
If you haven't already, you might like to make use of the search feature in the future to see if the issue has already been reported.
Quick Links:
📓 Issue Guidelines – 💬 Community Support – 📧 Customer Support – ✍️ Feedback and Suggestions – 📖 Game Wiki