No direct US to Budapest. Wish there were. I generally end up going through Frankfurt, but I depart from the other end of the earth compared to "The Bay Area".
I would prefer the order Prague, Vienna, Budapest as i always though of Budapest as more relaxing and its how i like to end a trip. And I would stay a little flexible. If one of the towns doesn't agree with you, then move on a day early. To do that you purchase your train tickets in-country when you arrive. We discovered Budapest when we got burned out on Vienna a few days earlier than we had planned.
I don't think it would be silly to book RT out of Prague if you could find a direct flight Budapest to Prague. I don't know of one, but check Ryan and Wizz (I didn't). I wouldn't spend a night on a train just to get back to Prague.
Really off the wall, look at RT costs to Istanbul. Then check one way Istanbul to Prague and one way Budapest to Istanbul. All on Turkish Air. Just might work. Or do it all as a Multi-City ticket. We have found some good prices through Istanbul in the past. Who knows.... might work...... YOu could also check Wizz and Ryand and find a major hub city with connections to both Prague and Budapest then buy a discount ticket to Prague and a discount ticket from Budapest back to the Ryan or Wizz hub.
Or add one more stop to your trip. BA / American fly through London and Delta through Paris. We've layed over for a night or two in each in one direction or the other to break up the long hauls.
ORRRRRRRRRRRRRRRRRRRRRRRR!!!!!!!!!!!!!!!!!!!!!!!! I know a lovely tour guide who will pick you up in Istanbul and drive you the length of Bulgaria and on to Budapest .................
OR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! well, sort of ideas right now. When and for how long do you travel??