There is another thread that brought this up (an older one)...
Here are the ways to get the coward trait (from export_descr_character_traits.txt):
;------------------------------------------
Trigger battle4
WhenToTest PostBattle
Condition not GeneralFoughtInCombat
Affects Coward 1 Chance 10
;------------------------------------------
Trigger random_birth1
WhenToTest CharacterComesOfAge
Affects Aesthetic 1 Chance 2
Affects Coward 2 Chance 2
Affects GoodSiegeAttacker 1 Chance 2
;------------------------------------------
Trigger battle7
WhenToTest BattleGeneralRouted
Affects Coward 1 Chance 25
You can see that in any battle where you general does not actually fight (don't know how "fight" is defined) there is a 1 in 10 chance of getting 1 point in the coward traits... But is no test on whether the other side withdrew unless it is something to do with "Trigger battle4"...
An interesting addition is:
;------------------------------------------
Trigger dads_coward
WhenToTest CharacterComesOfAge
Condition FatherTrait Coward >= 1
Affects Brave 1 Chance 20
Meaning if your dad is a coward you have a 1 in 5 chance of being brave...
Bookmarks