Marksburg and Rheinfels Castles:
The standard walks from town to castle in both cases involve some elevation gain. In case you aren't able or interested in walking up from town to the castles... For Rheinfels Castle there's a regular shuttle that runs between town and the castle on the clifftops. For Marksburg Castle, a local bus (#540) gets you from the station to the Johannisfriedhof stop. From there it's just a 9-minute walk to the castle. Because this bus runs only every 2 hours during mid-day hours (10:15, 12:15, 14:15...) it's wise to coordinate your train arrival time accordingly. Bus #540 schedule:
https://ekap-download.vrs.de/downloads/linien/mini-fahrplan/2023_3540_VRM540.pdf?1670826769
That said... because you listed "hiking" and the "Rhine's history" as interests, visiting both Rheinfels and Marksburg on foot seemed reasonable to me as "combo" activities.
Note that in both Braubach and St. Goar, and in Rüdesheim as well, you will find additional hiking options that can be very enjoyable. There's a hike from Rheinfels in St. Goar that takes you south along the cliffs through fields and forest to the Maria Ruh lookout for an outstanding view of the Loreley:
https://www.rlp-tourismus.com/en/infosystem/infosystem/Aussichtspunkt-Maria-Ruh_Urbar/infosystem.html
In Braubach, there are 20+ different hikes that include Marksburg Castle at the following site:
https://www.komoot.com/highlight/124376
Click on "see hikes here" in the green box near the top, right of center. The new page (P. 1) shows hikes 1-5 of the 22 hikes. On P. 2 you will find the most basic/direct trail up from the station. The walk up is labeled "easy" and estimated at 45 minutes (naturally, your time and energy level depends on many factors and may vary! Have a modest lunch if it's a hot day.) Look for the hike titled "Blick auf Marksburg – Marksburg loop from Braubach." Click on that trail for details and a map.
The path(s) to Maria Ruh from Burg Rheinfels or St. Goar are detailed at the same website. A hike to Maria Ruh and back would constitute a small segment of the longer hike titled "Spitzenstein mit Aussichtsturm – Loreleyblick Maria Ruh loop from Biebernheim," the route shown in purple and the first hike listed.
https://www.komoot.com/discover/Burg_Rheinfels/@50.1536330,7.7053740/tours?map=true&max_distance=30000&sport=hike&startLocation=&toursThroughHighlight=190798
I'd like to second travel4fun's suggestion for a stop in Boppard and for doing Boppard's Chairlift Ride. Very nice views up there from Gedeonseck terrace and the Vierseenblick lookout. I wonder if you might fit that into your travel day to Amsterdam. Possible schedule for Wednesday:
- 8:06 train from R'heim to Koblenz; store bags in locker during 24 m. layover. Train to Boppard (9:44) plus 2-min. bus ride #670 to chairlift (ar. 9:54, opens at 10:00.)
Then spend 4-5 hours on the lift and in Boppard before your trip to A'dam...
14:12 train to Koblenz (14:27)... or 14:40 train (ar. Koblenz 14:54)... or 15:12 - 15:27... or 15:39 - 15:53... for bags.
15:16 or 16:13 train departures from Koblenz to A'dam (both arrive before 9 pm.)