Relays are switches that are operated by electrical signals, as opposed to being operated manually. There are a many different types of these devices, and they each work in a somewhat different manner. The purpose of any relay is to be able to perform a switching function without requiring manual operation.
If you are familiar with relays at all, this is probably the type that you envision. There are many different styles, but they all operate using electromagnetic principles. To operate the relay, current is supplied to a coiled piece of wire. When the current flows through the wire, it causes a magnetic field to develop. This magnetic field, in turn, causes the physical movement of a magnetic switch which either causes the switch to become closed or open, depending on the type of relay. There are more configurations than you can imagine, but they all operate this same basic way, with a magnetic field being produced to cause the contacts in the switch to either open or close. When the power is removed from the relay, the reverse operation occurs, meaning if the switch was closed it is now open, and vice versa. The movement of the contacts is sometimes aided by a spring.
Solid State Relays
The other basic type of relay has no moving parts. When you hear the term solid state, you should think transistor, because all solid state means is some sort of transistor based configuration. A transistor can be thought of as an electronic switch with 3 connections, which are called the base, collector, and emitter for Bipolar Junction Transistors (BJT), or gate, source, and drain for Field Effect Transistors (FET). Relays are typically used in higher power applications, so the BJT would be used.
For the solid state relay, the electrical signal is sent to the base connection, causing a path for current flow to be created between the collector and emitter, and thus turning on the switch. When the power is removed from the base, the switch is turned off. If the circuit being controlled has a larger power requirement than a single transistor can safely pass, multiple transistors may be used in parallel.
This is how the two basic types of relays work. There are many variations on these simple concepts, but in the end all relays do one thing, which is to allow for the electronic control of a switch.