One of the most annoying things I experience when closing a tab in Safari is when it is the last tab and closing closes the entire window (including pinned tabs).
Thankfully, there is a simple remedy to fix this. In System Preferences go to Keyboard > Shortcuts > App Shortcuts and add a new shortcut for Safari, with the menu title of Close Tab and the command of ⌘W.
Done and done.