A spool piece is a smallish length of pipe used for two purposes:

Connecting pipeline systems

When laying subsea pipelines, there is a limit to how close to the target one can start and stop the pipeline. This is mainly due to the fact that platforms or ships stand in your way. There is also often a limit set by the owner of the system on how close your pipeline can come to other items on the seabed. Therefore the two pipeline ends to be connected together will be anything from 5 meters to 100 meters apart. In some cases this can be rectified by moving the pipeline while it is down on the seabed, but in most cases the problem is fixed by installing a spool piece.

Removing thermal expansion

If a pipeline carries a hot product, the material the line is made of will expand due to this added heat. This gives a slightly (mostly insignificant) larger diameter, but also (a very significant) lengthening of the pipeline. If the pipeline cannot expand, this lengthening will induce compression stresses in the pipeline and may cause buckling. By positioning an expansion spool on the ends of the pipeline this lengthening is allowed to happen, and the only stress increase one gets is a bending stress along the spool.

Geometric configuration of the spool is dependent on why it is put in. If only thermal expansion is an issue, the spool might look like a "U":

------\    /--------
      |    |
      |    |
This shape is most popular for spools in regular (above water) pipeworks. They can be fitted with a drainage valve or inspection port at the bottom of the U as well.
But other configurations are more common in the offshore oil industry:
L-spool:      Z-spool     

 |            ---\
 |               |
 |               |
 |               |
 |               \----
Both types allow for a long leg in the middle, so that the barge laying the pipeline can keep a good distance between herself and the platform.

The ends of the spool can either be fitted with flanges, set up for hyperbaric welding, or even contain some fancy remote mechanical connection tool.