How does The Hitchhiker's Guide to the Galaxy create humor and comedy?
One of the strongest techniques used in the book is that of simple exposition; by showing absurd situations and events as normal, the reader is invited to think about real-life events that are equally absurd. For example, the epic space-opera story of two species driven to war by an offhand comment from Arthur is told straight, with no hint of humor, until the last sentence:
For thousands of years, the mighty ships tore across the empty wastes of space and finally dived screaming on to the first planet they came across -- which happened to be the Earth -- where... the entire battle fleet was accidentally swallowed by a small dog.
(Adams, The Hitchhiker's Guide to the Galaxy, Google Books)
By showing the entire scenario to be absurd, Adams challenges the conventions of science fiction, where alien species are usually capable of communication on a human level. Because the exposition is presented calmly, almost scholarly, the eventual absurdity is much more effective, and similar scenes provide much of the humor.
The use of absurdity in examples, exposition, and metaphors, Douglas Adams creates comedy in his works. For instance he writes that a ship hung in the sky in very much the same way that bricks don't. Its not a conventional way to use metaphors but it works and its hilarious.