That's not mapping a PID to the window though - it's just destroying a window ID and seeing what happens to error out - which might not happen if the app was written to handle the window being destroyed outside it's control, or it's running on a different machine where you won't see any error output/a process dying.
You can kill the connection of another client if you know its id. That's one of the reasons why we love X11 so much.
Another way, as josefx mentioned, is to kill the PID from _NET_WM_PID window property. This is often used by window managers when they offer to kill an unresponsive application.