Replacing face-up cards when only two regular Train Cars remain
This would be a very rare situation, and the rulebook does not directly address it.
There are basically 2 options for how to handle it.

Simply leave the 5 face-up cards with them having 3 or more locomotives in the set. This is how the mobile and online versions are implemented.

Follow the rule for a similar situation that is mentioned by the rules:



In the unlikely event that there are no cards left in the deck and there are no discards (because players are hoarding many cards in their hands), a player cannot draw Train Car cards. Instead he may only claim a route or draw Destination Ticket cards.

It makes sense to follow this rule in this situation, because while it's not true that &quot;there are no cards left in the deck and there are no discards&quot;, it IS true that the cards that are left cannot make a valid set of face-up cards. So the recommendation would be to act as if there are no cards left, and not allow players to draw new train car cards until a route is claimed.
Source: https://boardgamegeek.com/thread/1812513/there-are-only-locomotives-left-deckdiscard