The modern London Borough of Hackney was formed by joining three former boroughs, one of which was also called Hackney. In the Middle Ages, this Hackney was originally a town outside of London, and the people there bred horses that had an excellent reputation. In time, the horses were referred to by the town's name.
The horses of Hackney, and horses similar to them, were often available for hire. The people who hired the horses put them to work doing all sorts of things, including pulling carriages. From that use, it was a natural extension to use the name hackney for a horse-drawn carriage kept for hire.
Eventually, connotation of the word hackney shifted from the horses and vehicles to the state of being available for hire, resulting in the more general, and now obsolete, sense of "one who does menial or servile work for hire," then the verb use, "to make trite, vulgar, or commonplace" (by indiscriminate everyday use), and the derived adjective hackneyed. Through the process of shortening, hackney became hack in its original sense of a horse for hire, then for the hired carriage, and ultimately for someone, such as a writer, who is only interested in making money (and often produces substandard work as a result).
Although there is a related verb sense of the noun hack (derived from hackney), it is not the source of hack referring to illegally accessing computers. That hack is distantly connected to the "chopping" sense of the word and may have roots in the Massachusetts Institute of Technology (MIT). An early documented technical use of the verb hack is in the minutes of an April, 1955, meeting of MIT's Tech Model Railroad Club: "Mr. Eccles requests that anyone working or hacking on the electrical system turn the power off to avoid fuse blowing." It is interesting that work was juxtaposed with hack: work implies sustained or continuous effort, whereas hack suggests irregular or unskillful strokes, if you will, of effort. Although a computer is not mentioned in the minutes, there is an electrical system being "hacked," which hints at the future use of hack in the computer field.
According to known usage evidence, hack in reference to computers is first manifested in hacker in the late 1960s.
Charles Landau did some of the programming, … and W. B. Ackermann helped when the machine would not cooperate. Many other computer hackers also willingly offered advice.
— R. J. Thompson, Instabilities some Time-dependent Flows, 1969
Send a computer science major over to join a research team, a computer 'hacker' to use a small DEC computer, and experienced programmer to get a programming job.
— Tech Engineering News, 1969
The earliest record of hack itself referring to the writing of computer programs occurs a few years later, which means that the verb may have been hacked from hacker.