macOS: Can I hide running apps with no active window from the Dock?
In general, majority of macOS apps are programmed to display it's icon in the Dock when it's running (exceptions are apps which display an icon only in the Menu bar when running).

If an app icon is not added permanently to the Dock, it's icon remains visible as long as it's running. The icon is removed from the Dock upon quitting the app by selecting App Name → Quit App Name from the app menu, or by invoking the keyboard shortcut Command + Q with the app in focus.

So, the only way to remove an app icon from the Dock is by quitting it.

Some apps are programmed to automatically quit when it's last visible window is closed either by clicking on the close button



at the top right, or when the close window keyboard shortcut Command + W is invoked.

Thus, it's up to the developer of the app to choose which of the two behavior to implement, and can not be changed by user.