And/or Graz. Or the Alps. No shortage of options. There's also Bratislava, if Slovakia is open; I haven't checked.
Slovenia's also lovely. Ljubljana is a charming, not-too-large capital city. The time you have available would allow you also to see Bled and a bit of the Julian Alps. Maybe also one of the caves.
I agree that the Croatian coast is a major detour, but if you are more city people than countryside people, you could combine Ljubljana with Zagreb. Those two cities are connected by both train and bus. Zagreb's larger and has more museums. It lacks the river Ljubljana has, but Zagreb's bi-level historic district is very nice.
BUT in terms of logistics, it seems fairly unlikely that you'll be flying out of Budapest if you have to implement your back-up plan. If you can't enter the country as tourists and have to make a last-minute change to your itinerary, won't it be difficult to arrange a flight to Budapest to connect with your current ticket? I'd recommend flying in the night before since you'd have a transatlantic ticket at risk, but in this situation you wouldn't be able to leave the airport. I wonder whether it would be a good idea to call your airline and see what the procedure would be if you cannot get into Hungary a week before you're supposed to fly home from there.
In any case, there are few flights from Ljubljana. You will find more from Zagreb, but neither city has direct flights to Budapest. You'd spend extra hours making a connection (likely more time from Ljubljana) and costs look really high to me. You can check your precise travel date on skyscanner.com.