I have never seen iCloud auto-archive an email. I don't even see any settings to make that happen, neither in Mail nor in iCloud.com. So, I have no idea how that is happening.
As to other accounts, Gmail essentially does that always. It isn't really IMAP, but pretends to be. It doesn't have folders, but "Labels." Multiple Labels can be assigned to a message. All messages come into your Gmail account with both an "Inbox" label and an "All Mail" label. The All Mail Label is mapped to the Archive mailbox in Mail.
Because it isn't really IMAP, messages on Mail end up in one folder or the other, and possibly both--quite abnormal for IMAP. The fix is to not use Gmail (or any other non-standard IMAP-like service) in Mail.
You can disable the viewing of Gmail's All Mail in IMAP in the advanced settings for Gmail under the Labels tab. That won't stop Gmail from marking them as both Inbox and All Mail, but you won't see the duplication in Mail.