The bug
While a mob is dying it still counts towards the mob cap.
To reproduce
/gamerule doMobSpawning false
Set difficulty to peaceful
Set difficulty back to another difficulty
Open F3 and observe the line starting with "SC"
Summon a husk
→ The "M" value increases by 1, indicating that the mob cap for hostile mobs increased by 1Kill the husk
→ ❌ The "M" value doesn't decrease again until the death animation stops
Related issues
relates to
Attachments
Comments

Confirmed. Probably affects older versions too, but I did not test that.
It does, Scicraft experienced it in 1.12.2, and maybe even 1.8, it is a very old bug.
A way to fix this bug would be by giving all mobs in their "death phase" the persistence required tag.
Affects 1.17
Can confirm in 1.17.1 Pre-release 1.
Can confirm in 1.17.1 Pre-release 3.
Can confirm in 1.17.1 Release Candidate 2.
Can confirm in 1.17.1.
Can confirm in 21w38a.
Can confirm in 1.18 Pre-release 5.
I don't think anyone would notice it if this got changed.
Additional note: If the mob is holding an item and is killed, the corpse will appear as if it is still holding the item, but the item is dropped before the corpse disappears.
Can confirm in 1.18.1.