Basically it started because some websites used to sniff the user-agent to tell what browser someone was using so they could block browsers that they thought wouldn't work with their websites. Specifically, websites were blocking Internet Explorer because it didn't offer as many features as Netscape Navigator. Instead of simply building a website that works across browsers, webmasters chose to just block IE completely. To get around that, Internet Explorer started to put Mozilla in their user-agent (with "compatible" in parenthesis).
Another reason is some browsers share the same rendering engine. For example, both Safari and Chrome use the webkit rendering engine. Firefox and SeaMonkey both use gecko. As a result they will both have pieces of their user-agent which will match and/or mention the other browser.
This article has a good summary of user-agent history in much more detail.