When you kill a flying mob, it falls and does damage to you. When a mob is dead, during its death animations it shouldn't be allowed to hit you.
I believe it is a bug. Some people try and say it's lag or being too close while killing it, but this is not the case.