Here's how it likely evolved:
* Fishing: When a fish bites a hook, it's "on the hook". To release the fish or bring it in, you need to "take it off the hook".
* Figurative meaning: Over time, this literal meaning transferred to a figurative one, meaning to be free from a difficult situation or responsibility.
For example, if you were in trouble with your boss but then a new project comes along that your boss is excited about, you might be "off the hook" because the boss has forgotten about your previous mistake.
The exact origins of the expression are difficult to pinpoint, but the fishing connection seems to be the most likely explanation. It's a fairly old expression, with evidence of its use dating back to the early 1900s.