Bail can be a verb or a noun. When you bail (verb) someone out of jail, you post money, also known as bail (noun), to assure the authorities that person won't try to run away before going to trial.
As a noun, bail means bond money. This comes from the Middle English word bayle, for "captivity." As a verb, the idea of "bailing out" comes from the later word baile, which means “dipping out,” a meaning you can use when you are trying to empty something flooded. If your boat has a leak, you should bail it out (then plug the leak). When you bail, in the colloquial sense, you escape in some way.