When using any tool to attack any entity, the tool loses durability.
However this durability is also lost on a hit that is not registered as an attack, which is a bug. (I think)
This happens when the player attacks the entity but the entity is still in a time period of invincibility due to the previous attack, so the entity is not damaged but the durability of the tool being held is still incorrectly decreased.
In other words, this bug occurs every time the player spam clicks to kill an entity.
To repeat this bug:
Be in survival.
Hold a tool such as a wooden sword.
Spam left click on a trapped mob, in attempt to kill the mob. The faster you click, the more obvious the bug.
See the tool's durability rapidly decrease, even in between the actual damage inflicting hits.
Link to video of bug:
In the video above, the wooden sword should still have 40/60 durability remaining after killing the iron golem. But because I was clicking as fast as I could with my hand, some hits were incorrectly registered, and the durability still decreased for these unsuccessful attacks.
(Sword broke whilst killing the iron golem)