I'm pretty sure there are lots of people in the industry who write unmaintainable code on purpose for their own job security. I don't endorse this, but I've heard horror stories at several well-known companies about instances of this.
It might be revenge though, not job security? Or maybe "organic" local job security, i.e. the colleges of the perpetrator can't take over his tasks easily without management investment?
I guess most bad code is just bad/novice programmers or bad project management.