You're confusing a hash function with a compression algorithm.
A hash is typically a one-way operation, that is there's no way to "un-hash" something once it's hashed. That's fine as that's not what hashes are used for.
Hash functions are normally used to represent something of arbitrary length as a consistent length value. For example SHA2-256 represents an arbitrary amount of binary data as a 256-bit value. It's designed so that even a single bit change in the input causes the whole hash to change, making it difficult if not impossible to reverse the hashing process and "guess" the input.
This not to say hashes are without flaws. MD5, famously, is so weak that it's not hard to construct two binary strings that hash to the same value, generating a hash collision. A good hashing algorithm makes this unlikely, but no hashing algorithm can ever make it impossible.
Things hashes are used for:
- Providing a "digest" of something in order to detect tampering, as in cryptographic signatures of things you download.
- Distributing data "randomly" across a data structure to avoid clumping, as in a hash-table or dictionary.
- Storing data that should not be easily reversible, like passwords. A good password hash is very hard to brute-force guess, but reasonably easy to test against a candidate password.
There's basically an infinite number of binary documents that could create a given MD5 hash. This is not true with lossless compression algorithms, as the compressed representation by design represents one and only one source document.