Hi, trains are very comfortable in Spain but for sure you will enjoy much more if you connect both cities with a road trip. Zaragoza is a mid-sized city, famous mainly for El Pilar Basilica. La Aljaferia is also a must-see in Zaragoza. From Zaragoza I´d recommend you head west and get to Pamplona, where the San Fermin Fiestas take place every year in July, then Logroño to enjoy one of Spain´s best tapas districts (Calle Laurel) In Rioja I´d recommend you visit the Monastery of Yuso and also enjoy hiking, you could walk along pilgrims near Santo Domingo de la Calzada, which is an important stop in El Camino de Santiago.
An interesting next stop could be an amazing village, hardly known, called Frias. But before that, I forgot to mention that in Rioja you will be able to enjoy great local food and wines. Haro is well-known as a very interesting town for wine lovers.
From Frias you drive south to Burgos, which holds an amazing cathedral and good (but heavy) gastronomy. Further South Lerma is an interesting small town to spend a night, and I´d strongly recommend Segovia before you get to Madrid. Depending on how much time you want to spend in each place, and if you are really into food, maybe instead of driving south from Rioja you could head North to San Sebastian and/or Bilbao. San Sebastian has an amazing beach and holds lots of amazing restaurants and bars. Bilbao is home to the Guggenheim Museum, and in the old district, you will enjoy many amazing tapas bars as well. This itinerary could give you some hints for you to prepare a quality road-trip. https://privatetoursofspain.com/397/madrid-san-sebastian-and-barcelona-gastronomy-tour/