How did "bail" shift to signify "money deposited as a guarantee when released"?
I fail to understand this etymology for bail (n.1), particularly the first paragraph.
[3.] "bond money, security given to obtain the release of a prisoner," late 15c., a sense that apparently developed from that of
[2.] "temporary release (of an arrested person) from jail" (into the custody of another, who gives security for future appearance at trial), which is recorded from early 15c.
That seems to have evolved from the earlier meanings [1.] "captivity, custody" (late 14c.), "charge, guardianship" (early 14c.).
The word is from Old French baillier "to control, to guard, deliver" (12c.), from Latin baiulare "to bear a burden," from baiulus "porter, carrier, one who bears burdens (for pay)," which is of uncertain origin; perhaps a borrowing from Germanic and cognate with the root of English pack, or perhaps from Celtic. De Vaan writes that, in either case, "PIE origin seems unlikely."
How did [1.] "captivity, custody" shift to mean [2.] "temporary release (of an arrested person) from jail"? If a prison RELEASES an arrestee, then undeniably the arrestee is no longer under the prison's CAPTIVITY or CUSTODY!!?!?! Unquestionably, "release" is the opposite of "captivity" or "custody".
Then how did [2.] "temporary release (of an arrested person) from jail" shift to signify [3.] "money deposited as a guarantee when released"? These are two wholly different notions! "temporary release" is a physical act, and differs from "money" that is property.
What semantic notions underlie senses 1, 2, 3?
bail There are now three distinct words bail in English, although they may all be related. Bail ‘money deposited as a guarantee when released’  comes from Old French bail, a derivative of the verb _baillier _‘take charge of, carry’, whose source was Latin bājulāre ‘carry’, from bājulus ‘carrier’. Bail ‘remove water’ , also spelled bale, probably comes ultimately from the same source; its immediate antecedent was Old French baille ‘bucket’, which perhaps went back to a hypothetical Vulgar Latin *bājula, a feminine form of bājulus. The bail on top of cricket stumps  has been connected with Latin bājulus too – this could have been the source of Old French bail ‘cross-beam’ (‘loadcarrying beam’), which could quite plausibly have been applied to cricket bails; on the other hand it may go back to Old French bail, baille ‘enclosed court’ (source of English bailey ), which originally in English meant the ‘encircling walls of a castle’ but by the 19th century at the latest had developed the sense ‘bar for separating animals in a stable’.
Word Origins (2005 2e) by John Ayto, p 46, Right Column.