It's also to do with which units die first in a battle, without a shadow of a doubt.

E.g. If you assault a stone wall with say a unit of Pedites as Rome, and they win but lose 90% of their number, then after the battle (as long as you win and have a General with a <healer> anciliary), you'll get most, even all of them back sometimes.

This is true without exception to my knowledge. You seem to get a percentage of the total casualties back (assuming a healer ancil). The chirgeon seems to heal more than the doctor, who heals more than the herbalist. Then a random percentage is applied on top of that. Whoever gets "killed" first seems to have the highest chance of being healed, with those falling to missile fire also having a high probablity.