Presumably the rate chart of the cab is known. It's not a random number that springs on you months after the ride with no real logic other than 'this is how it be'.
Except the driver has discretion to choose a path and it’s easy to take a longer route when the passenger is not a local. Likewise it’s easy for hospitals in the US to pad their charges arbitrarily (e.g. $50 for a Tylenol/Panadol tablet, a genuine example)