Here's how to keep the contents of both Junk folders the same between iCloud Mail and macOS Mail:
- Open the Mail app on your Mac.
- Choose Mail > Preferences.
- Click Junk Mail, then select “Enable junk mail filtering” and “Move it to the Junk mailbox.”
- Click Accounts.
- Select your iCloud email account on the left.
- Click Mailbox Behaviors, then click the menu next to Junk Mailbox. Under iCloud in the menu, choose Junk.
Now, all messages marked as junk are stored on the iCloud server and you can see them in the Junk folders of both macOS Mail and iCloud Mail. If you delete a message from either folder, you delete the message permanently.
Since junk mail on the iCloud server counts toward your iCloud storage limit, you might want to delete junk messages regularly. Messages in the Junk folder are deleted automatically after 30 days.