I like to make connections so I can remember keyboard shortcuts. I get Ctrl+T to open a new tab - but what's the logic behind Ctrl+W to close one?
It was absolutely "stolen" or "borrowed" from Mac OS. Windows originally used Alt+F4 to close windows, but they realized that was a sub-optimal (read: dumb) choice.
W was chosen because of its close proximity to Q which was the obvious choice for a [Q]uit keyboard shortcut.
Apple was very keen on having every piece of software either internally or by a third party follow a set of human interface guidelines. Included in these guidelines was this, among many other things. Microsoft and Windows were much more open to allowing developers to do whatever they chose, and ignoring many conventions, certainly around how keyboard shortcuts worked. I certainly remember a lot of early windows software that had unique cut/copy/paste shortcuts.
For instance, even in Windows 7 Notepad doesn't close with Ctrl+W, you have to use Alt+F4, or Alt, then F, then X.
Another example is the command prompt. Even in 2014, you can't copy and paste like a normal human being, you have to first mark an area of text and then use the enter key to copy it. Likewise to paste, you right click, because why make everything the same? That's boring...
This is the oldest copy I could find of Apple's Human Interface Guidelines. On page 102 it says this:
While this copy of the HIG is from 1995, this convention was on the Mac before even this, perhaps as early as 1986.
There is even this internet gem talking about how Adobe products (on Windows) don't follow the convention used by Firefox:
The answers suggesting AutoHotKey and the like are to a Mac user laughingly complex and unnecessary.
There's this as well
It was stolen from the MacOS, which uses Command-w to close the current tab (for applications with tabs) or the current window. Note that Command-q is used to quit the application, so Command-w, which is one key over, probably seemed like a good choice to close a window.