Haywire is used on farms to hold together bales of hay.
It’s tightly bound and when cut will sometimes whip around in a dangerous, erratic manner.
But more than this, because haywire is often used as a temporary repair on machinery that has broken down, or to hold together any equipment that’s falling apart
The word became a rural expression for things or people that aren’t functioning properly, as in, they’ve gone haywire.