The one under iCloud is on the server, put there by iCloud, and it contains messages flagged as junk by the iCloud junk filter. The other is on your Mac, put there by Mail, and it contains messages flagged by Mail's Junk filter.
Highlight the junk folder under the iCloud folder and select Use This Mailbox For under Mailboxes in the menu and select Junk. This will map the imap junk folder to Mail's junk mailbox. If it pushes the local iCloud Junk folder created by Mail under On My Mac, you can delete it.