ssh -X is the executable copied and run locally or is it run on the host machine. Since it is called X11 forwarding it makes me think that the window is drawn on my machine but running on the host.
The executable is run on the remote machine and displayed (drawn) on the local machine. What
ssh -X remote does is start up a proxy X11 server on the remote machine. If you do
echo $DISPLAY on the remote machine, you should see something like
localhost:21.0. That is telling the program running on the remote machine to send drawing commands to the X11 server with id 21. This then forwards those commands to the real X11 server running on the local machine, which draws on your screen. This forwarding happens over an encrypted ssh connection, so they can't be (easily) listened to.
Unlike Windows, Mac OS, etc, X11 was designed from the beginning to be able to run programs across a network, without needing things like remote desktop. For a while, X11 thin clients were popular. It is basically a stripped down computer that only runs a X11 server. All of the programs run on some application server somewhere.
The application runs remotely, except the X components (i.e. rendering the x-commands etc) which are running locally. Every client application usually uses the local X server to display the UI. In this case, the commands are send via the encrypted SSH channel from the remote machine to your local machine and are displayed there.
$DISPLAY is only half of the deal though. In order to be able to authenticate the clients on the server side,
ssh also utilizes
xauth to create a new authentication cookie. See
xauth list and
The key may be to realize that the X server is a single thing which provides graphics to a user, and all the different programs which want graphics have to be X clients and connect to a server. The interface between client programs and the X server was designed from the start to support connections with remote programs, not just those on the local machine.
In a crazy enough network, a program could be run anywhere and display its graphics anywhere else...