Minecraft wiki entry for Damage, associated text: A player must be falling.
A player must not be on the ground.
A player must not be on a ladder or any type of vine.
A player must not be in water.
A player must not be affected by blindness.
A player must not be affected by Slow Falling.
A player must not be riding an entity.
A player must not be faster than walking (like flying or sprinting.‌[Java Edition only])
A base attack must not be reduced to 84.8% damage or lower due to cooldown.‌[Java Edition only]