I was able to delete the hidden folders that existed in the root of my iCloud Drive from iOS and macOS that apps I'd previously deleted from my devices.
I'm using macOS Catalina version 10.15.2 but this may work on earlier versions of macOS.
Open Terminal.app and type this but do not press return yet:
Make sure there is a space after the "f" at the end of the command
In Finder, open the iCloud Drive folder and change it to List view (command+2) so you can easily see all of the hidden folders.
Select all of the folders you want to delete, then drag them in to the Terminal window. It will automatically add the path of the folders to the command, separated by spaces.
So the command would look something like this:
rm -rf /Users/username/Library/Mobile\ Documents/com~apple~Automator/Documents /Users/username/Library/Mobile\ Documents/com~apple~ScriptEditor2/Documents /Users/username/Library/Mobile\ Documents/com~apple~TextEdit/Documents /Users/username/Library/Mobile\ Documents/com~apple~QuickTimePlayerX/Documents /Users/username/Library/Mobile\ Documents/6LVTQB9699~com~seriflabs~affinitydesigner/Documents /Users/username/Library/Mobile\ Documents/iCloud~net~doo~scanbot~vpp/Documents /Users/username/Library/Mobile\ Documents/com~apple~Numbers/Documents /Users/username/Library/Mobile\ Documents/F6266T9T75~com~apple~iMovie/Documents /Users/username/Library/Mobile\ Documents/com~apple~Keynote/Documents /Users/username/Library/Mobile\ Documents/WUGMZZ5K46~com~bohemiancoding~sketch/Documents /Users/username/Library/Mobile\ Documents/iCloud~com~readdle~Scanner~PDF/Documents /Users/username/Library/Mobile\ Documents/iCloud~is~workflow~my~workflows/Documents /Users/username/Library/Mobile\ Documents/F3LWYJ7GM7~com~apple~garageband10/Documents /Users/username/Library/Mobile\ Documents/com~apple~Preview/Documents
Press return. It may ask you for your computer password.
After running the command, nothing will happen in the iCloud Drive window.
The only two things I observed at this point that were different from before were:
a. When clicking on of one of the folders, the Finder Path Bar will show iCloud > and the folder's icon, but will not show the folder name
b. Dragging the folder to Terminal again does nothing - it does not generate the text path like before.
Restart your Mac
Return to iCloud Drive in Finder and the hidden folders should be gone.