Telegraph signals weaken as they travel down a wire; beyond a certain distance the original signal can no longer power a receiver. So what do you do? You say, well, let's have an intermediate telegraph operator: he can be stationed where the signal is still intelligible, and simply re-transmit what he receives, using his own power supply to generate a full-strength signal.
And then someone clever realizes you can use an electromagnet to operate the re-transmitting key and the incoming line to power it. Yes, the first relay was a telegraph key with an electromagnet stuck on it.