"bond money, security given to obtain the release of a prisoner," late 15c., a sense that apparently developed from that of "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 "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."
To go to(or in) bail "be released on bail" is attested from mid-15c. In late 18c. criminal slang, to give leg bail meant "to run away."