Welcome to the forum. You can drop the car anyplace in Germany that your rental company has an outlet. Many companies have rental drop options at your local train station or nearby.
There's no reason to drive (or take the train) into Mainz, specifically, if you just want to focus on the scenic part of the Rhine. Travel to Bingen by train and take your cruise from there to St. Goar. If you take the train from Bavaria, you arrive in Bingen, walk to the boat dock, and cruise north to St. Goar for a river-based view of the castles, cliffsides and attractive towns. Or travel by car to any nearby city just south of Bingen where you might find a convenient rental drop - Mainz, Wiesbaden, or perhaps Bad Kreuznach might work. You can then take the train from any of those towns to Bingen.
I wouldn't keep the car to Cologne. If you do that you have to backtrack by cruise boat or train to Bingen to fetch your car.
The Middle Rhine Valley has frequent trains on both sides of the rivers and like almost everywhere in Germany, train service is nearly around the clock and largely efficient. If you stay over in St. Goar you can easily day trip to Bacharach, Oberwesel, Boppard, and other towns of interest nearby by train. See this map with rail lines (and hiking trails.)
I would encourage you to think of the Middle Rhine Valley as much more than just a river cruise. There's a lot to see and do there.