Short answer: Cmd W closes one tab. When a whole window of tabs disappears, it was Shift Cmd W, the last tab in the window, or Cmd Q. Press Shift Cmd T to bring them back, and add a confirmation or remap the key so it cannot happen again.
Remap Close Window. System Settings › Keyboard › Keyboard Shortcuts › App Shortcuts, click +, pick the browser, type the menu title exactly as in its File menu (for example Close Window), and assign a chord you will never hit. Shift Cmd W then does nothing in that browser.
Ask before closing. Still Dock's direct download asks before Cmd W closes in the apps you choose; the Mac App Store version needs a second Cmd W. Every other app behaves normally. It is part of Still Dock Pro.
Reopen on launch. Safari › Settings › General › Safari opens with: All windows from last session. Chrome › Settings › On startup: Continue where you left off.
Hitting Cmd Q when you meant Cmd W? See Cmd Q is too close to Cmd W and Cmd Tab.
Not per tab. Pin the tab in Chrome or Arc to make it harder to lose, and use Shift Cmd T if it goes.
It reloads the page. Text typed into a form is usually lost.