Hack has two distinct, and, as it turns out, opposite meanings.
A hack was originally a clever or unique way of solving a particularly complex computer problem. Typically, a hack is an inelegant shortcut that might elicit the comment, “It’s not pretty, but it works”.
More recently, hack has come to be seen as a general term for breaking into protected computing resources via technical means.
It makes some small amount of sense that the second definition might follow from the first, because break-in attempts are often inelegant and crafty shortcuts – hacks – that bypass or compromise the target’s design.