A similar quote appears in Robert Heinlein's 1941 short story Logic of Empire: "You have attributed conditions to villainy that simply result from stupidity." It is possible that the term 'Hanlon's Razor' is a bastardisation of 'Heinlein's Razor'.
This maxim is also widely attributed to Napoleon Bonaparte.
General observations on the predominance of human error over malice occur in various works of literature; Goethe's The Sorrows of Young Werther (1774) mentions: "[...] misunderstandings and neglect create more confusion in this world than trickery and malice. At any rate, the last two are certainly much less frequent."
Quoted here because it seems to be a particular favorite of hackers, often showing up in sig blocks, fortune cookie files and the login banners of BBS systems and commercial networks. This probably reflects the hacker's daily experience of environments created by well-intentioned but short-sighted people. Compare Sturgeon's law.