Raid ends as defeats when a single villager loses its job.
Note: I do not know if this is an intended feature or not.
To reproduce:
Find a single villager with no other villagers around.
Give him a job block and let him take the job block. (Do not trade with the villager.)
Start a raid.
Destroy the job block which the villager took. (My villager lost its job suddenly.)
Please provide some screenshots or videos of this issue occurring whilst the F3 debug screen is enabled.