Raspberry Pi GPIO using a relay switch
The Raspberry Pi GPIO outputs (and outputs on most other microcontrollers) can only deliver a few mA, and even a small relay will require more current than the GPIO can handle.  The site you link suggests keeping the GPIO output current below 3 mA, and suggests that the relay may require 50 - 100 mA.  

A very small current into the base of a transistor can control a much larger current through its collector - it effectively amplifies the GPIO output to a level that can safely control the relay.