macOS: App icon remaining in Dock even after closing app
macOS Mojave introduced a feature to show recently launched app's icons in the Dock, even after quitting the app. To a new user of macOS, even if they have been using earlier releases of macOS for a while, this may give an impression that either the app is still running, or the icon got persistently added to the Dock. To disable Dock from displaying recently launched app icons in the Dock, go to System Preferences app → Dock and uncheck Show recent applications in Dock. This setting is enabled by default in macOS Mojave.





While this was not the reason in this particular case, some other reasons this may happen are discussed below:

A macOS app is generally (well in majority of cases) programmed to show it's icon in the Dock when it's launched. (There's an exception to this general rule, an app can be programmed to run and show their icon only in the Menu bar).

Unlike other desktop operating systems, a macOS app generally doesn't quit when you click on the close button (shown in red below):

 

Clicking the close button generally close the app window and doesn't necessarily quit the app. The app keeps running. (I said generally, because some app are programmed to quit when the close button is clicked).

The way to quit an app completely is either to use Menu bar command App Name → Quit App Name, or to use the universal keyboard shortcut Command + Q. This will always quit the app and remove it's icon from the Dock (if the icon wasn't present in the Dock before app was launched, and you haven't enabled Keep in Dock from the app's Dock icon's context menu).

If an app icon is not present in the Dock before it is launched, it doesn't automatically gets added to the Dock when the app is run.

Another possible scenario where the app icon remains in the Dock happens when you have manually rearrange it in the Dock. Once an app icon is moved to a new location in Dock, the Keep in Dock option in the Dock icon's context menu gets checked. This is by design.

As far as automatic launch of iTunes is concerned when an iPhone (or any other iOS device) is connected to your Mac, you can turn this off. Launch iTunes and open iTunes preferences by using Menu bar command iTunes → Preferences... or using keyboard shortcut Command + ,, go to Devices tab and check Prevent iPods, iPhones and iPads from syncing automatically.