Hi!
Travelling by rail from Santiago de Compostela to the Algarve by rail will be convoluted and will probably entail at least 3 changes and you may not be able to buy tickets online.
I would suggest that a trip by coach may be quicker and easier:
The Portuguese Coach company Internorte advertise a twice daily service from Santiago de Compostela to Lisbon with departures from Santiago de Compostela ESTACION DE AUTOBUSES at:
Dept: 22:00 Arrive Lisbon Gare Oriente 05:45
Dept: 10:00 Arrive Lisbon Gare Oriente 18:00
Their web-site is here:
http://www.internorte.pt - Click on Horarios to download their huge timetable in pdf format and scroll to Page 50.
From the same bus station in Lisbon you can then connect with RENEX bus services to the Algarve departing at 07:30 and 19:00 respectively. Trips take about four to five hours depending on destination.
You can download the RENEX timetable from my blog:
http://barlaventostravelblog.blogspot.com/
Scroll down on the right until you come to:
Algarve & Portugal - Travel Transport Links
Click on:
RENEX Bus Service - Lisbon to Algarve timetable
If you are determined to go by train you will have to get a RENFE (renfe.es) service in Spain from Santiago da Compostela to Madrid, then connect to a train to Lisbon and then yet another train to The Algarve. (See Portuguese Railways at: www.cp.pt)
The only connection would be as follows:
Train: 00152 TALGO
Santiago da Compostela 13:37 21:32 MADRID
Train: 00332 TRENHOTEL
Madrid 22:45 Lisbon Oriente 07:45
Train: AlfaPendular
Lisbon Oriente: 08:40 Tunes(Algarve) 11:24 (Junction for all destinations on the Algarve Line.)