In essence, a window manager is just as its name implies. A Window Manager is the program responsible for coordinating all the the windows on the screen.
To answer this question more fully, it is useful to take a step back and describe the other pieces of the system the a window manager works with. These other pieces are X Windows and the applications that are displaying windows on the screen.
X Windows, like many Unix applications and utilities, is designed around the concept of modularity. If you do one thing well and are set up to cooperate with other programs, the resulting power and flexibility is amazing.
X Windows itself is an application that runs on top of the operating system and provides an interface to the graphics output hardware and input hardware, such as the screen, mouse and keyboard. By providing a standard set of routines for accessing the input and output hardware, a programmer can focus on their particular application and leave the burden of low level hardware interaction to X Windows. Any program that requests the ability to display things to the screen is given a window or set of windows and is notified or various events the related to those windows and and user input that happens while those windows are active. The other powerful feature of X Windows is that it handles all of its communication with other programs over socket connections. This means that the program doesn't even have to be running on the same computer that the user is interacting with. This has some very valuable advantages. Essentially, this is the functionality that X Windows provides. One thing that X Windows does not provide is management of which windows are active at any given time and whether there are any specific restrictions as to where and how large each window would be. Individual applications can set these attributes themselves, but X Windows is not enforcing any sort of general policy as to how these windows are managed. In the grand tradition of Unix's modularity and cooperation, X Windows does provide a set of hooks for an application to set in and fulfill this roll. This is where a window manager comes in.
The job of a window manager is to handle how all of the windows created by various applications that share the screen and who gets user input at any given time. As part of the X Windows API, applications supply a size, position and stacking order for each window they create. In actuality, these values are suggestions for the system to take into consideration. The window manager is the program that actually decides what the real size, position and which windows obscure other windows if the windows overlap. The window manager is also reponsible for determining which window is currently receiving the user's input.
As stated above, X Windows provides a set of hooks for managing all of the windows and user input of the system. Windows themselves are arranged in a hierarchy. Each window may contain sub-windows. This is how most applications create the various pieces of their user interface. For example, an application can create a main window and add a sub-window that looks like a button. Each window has a set of events associated with it. For the example of the button, the application requests that anytime the user clicks the mouse on that button (ie. window) then it should be notified. Typically most applications don't do this themselves, but rely on what is called a widget set to provide all of the standard user interface components for them. Getting back to the idea of a window manager, each window has a set of hooks associated with it that allows a program to manage the window's sub-windows' requests for changes in size, focus and position. Only one program register these hooks for a given window at a given time. Applications and widget sets use these hooks to manage the user interface for each program.
A window manager is simply a program that uses these hooks to manage the windows that are children of the root window (ie. the screen). Typically a window manager adds a title bar to each main window (each window that is a child of the root window) and adds borders that the user can user to move and resize the windows on the screen. The title for each application is also taken from a suggestion by each application. Without a window manager running, the user tends to be stuck with whatever the default size and position each window starts with. By using a window manager, the user gets a consistent behavior for all of the main windows on the screen. Generally, a window manager honors the size and position requests for each window and then allow users to explicitly move or resize the window, changing these parameters as they see fit. The window manager also determines which windows are visible when windows overlap. Sometimes a window manager has a special layout or policy in mind. If this is the case, the window manager sets the window geometry acording to its own rules and it is the job of each of the applications to work within these rules.
There are two final responsabilities that a window manager should undertake. The first is the screen's colormap. Managing the colormap basically provides arbitration when two applications have different demands about which colors can be displayed on the screen at any given time. The other task is focus management. This means which application gets access to the user's mouse and keyboard input at any given time. The default X Windows behavior is the grant focus to the window that the mouse is over. Many window manager modify this behaviour to take key commands and other more sophisticated focus models into account.