cmd-w to close pinned tabs
As a workaround, I'd set up a keyboard shortcut in Safari for both Pin Tab and Unpin Tab to the same shortcut, e.g., ⌥⌘P and then you can toggle the pinned status of the Tab with the same keyboard shortcut.

This way when a Tab is pinned and you want to close it, using the keyboard, you'd first press, e.g., ⌥⌘P then: ⌘W

System Preferences > Keyboard > Shortcuts > App Shortcuts