Why do cryptographic hashes need to be fixed length? Why do cryptographic hashes need to have a fixed length output?

I know that the shallow answer is that an output that varies by key size or file size can leak information somehow, leading to cryptanalysis, but I would like some more intuition as to why this is the case.

In the case of using an HMAC, like HMAC-SHA256 or HMAC-SHA1, is it still the hash (SHA256 or SHA1) which is ensuring that the output is of a fixed length? Or does the HMAC algorithm come into play as well?
They don't, and in fact the sponge construction used in Keccak (SHA-3) allows for variable length output. 

In other hashes the Merkle-Damgård construction was used which has a fixed output length due to the nature of its design. But there is no reason to not allow for variable output length other than ease of development or use.