Our cruise ends in Basel. We plan to take train back up to Amsterdam spending five days along the Rhine.
We would like to see some castles, interesting towns, maybe go to Stuttgart for a day. We will not have a car. Just plan to use the trains and work our way back up to Amsterdam.
Would like to stay at two hotels along the river route for 2-3 nights each and take in a few day trips to see some sites (within 2 hours of hotel).
What are some good base towns along the river to stay and see some interesting sites?
Koblenz does not get much attention on here, but it offers great access to the middle Rhine and the best castles, as good access to the Moselle Valley and it's small towns and wineries. If you feel like a day at the baths, Bad Ems is just outside Koblenz.
Stuttgart is a bit far from there, better hit enroute to Koblenz, maybe worth a night. Only about three hours from Basel, but it is off the main rail line from Basel to Frankfurt and on to Amsterdam.
What time of year is this going to be?
Mid August
For CASTLES and attractive old-world towns: You probably will like BOPPARD, a really good base town for train travelers just south of Koblenz in the most scenic part of the Rhine, the Upper Middle Rhine Valley between Koblenz and Bingen (also called the Rhine Gorge and the Loreley Valley.) See map:
http://www.loreley-info.com/eng/rhein-rhine/walking-hiking.php
https://www.boppard-tourismus.de/media/was-ist-wo-broschu__re_en_190218.pdf
Boppard has a wide choice of lodging and dining options (including riverfront hotels) as well as proximity to other old-world towns of interest, and it's on the day cruise circuit as well. Your room there comes with a free train transport ticket for local outings during your stay.
What we do not know from your post are the towns that you might already have visited during your cruise before you reached Basel. I wouldn't wish to send you places you have already been.
The map below shows a wider area which includes the Rhine Gorge - follow the Rhine south from Bingen to Karlsruhe to locate other towns of interest. Speyer, Worms and Mainz are Rhine cities that I find interesting for a variety of reasons. It also shows all the train routes you might use in the general area.
https://www.vrminfo.de/fileadmin/data_vrminfo/PDF/RLP-Ticket_streckennetz.pdf
The next map covers the Rhine region and the area's railways just to the south, from Karlsruhe to Basel.
https://www.agilis.de/wp-content/uploads/2016/11/Streckenkarte-BW-2013.jpg
Stuttgart is on the Neckar River - if you have chosen to go there already, you might look nearby at Esslingen, Tübingen and Besigheim, all Neckar River towns. These places tend to be more attractive than Stuttgart as a rule for most people, and they are more attractive than the Rhine towns nearby as well, generally speaking.
"...some good base towns along the river....?" I would suggest Koblenz where Deutsches Eck is located, the point where the Rhine and Mosel meet. If you want a smaller place, then Boppard , suggested above, or bad Ems.
Historically and culturally, both Bad Ems and Koblenz are significant.
Last summer I took a late afternoon trip to Bad Ems after arriving at FRA that morning, (the train was over 30 mins arriving in Koblenz Hbf, should have changed in Limburg an der Lahn instead), realised immediately that a day trip Bad Ems is going to need a lot more time in seeing the salient historical sites .
Are you interested in Stuttgart for the car museums ? What are you seeing on the cruise ? What are your ports ?
I like the already mentioned Tuebingen. I stayed for a week last time, 4 days the previous visit. Along the middle Rhine there are several possible towns to stay at. Staying in Boppard can save a little on transportation, but in the grand scheme of things, it is not much. I’ve stayed about a month in Bacharach, a week in Koblenz. I’d look for an accommodation that you like. Maybe the castle Auf Schoenburg in Oberwesel if you want to splurge. You could also see if any of the towns between Koblenz and Cologne strike your fancy.