The word 'retrieve' means to get something back or to recover something.
In the above sentence, 'The dog was trained to retrieve the ball', the word retrieve refers to the that the dog was trained in getting the game or ball back as wherever it was thrown.
Synonyms of word retrieve are, recovery, retreat, bring somethings back replace and so on.