I've visited several interesting, quaint, smaller towns that are on the train line. But note that my Spain trips have always been in November or December, so I can't judge their "tourism quotient" in high tourist season, if these towns even have one.
One of my favorites is Teruel, in Aragon, I think around 90 miles south of Zaragoza, which I saw in 2009. An aesthetic town, with a great renaissance-looking center, and medieval neighborhoods beyond. It's known (insofar as it's known at all) for its its late-medieval Mudejar towers, this being an architectural style developed by muslims "left behind" after the Christian reconquest. Other quaint medieval towns, like Albarracin, can be reached by bus.
In Extremadura, I've also visited Trujillo and Zafra, both of which I can recommend. There are several others in that province as well.