Trade routes can vary hugely in value, between games and even between cities. A small city on a pangea continent with limited foriegn cities to trade with might get just 1 commerce. A massive Temple of Artemis + harbour capital city on a different continent from many foreign civs might get upwards of 15 commerce commerce or more. Most likely is probably 2-4 commerce in a decent sized city as long as you have some foreign trade partners.
Then you must consider the commerce multipliers - is this a city with a library and university? Does it have Oxford? Bank and market, and you are running low science slider? This is one of the few multiplicative modifer situations in Civ IV - good trade routes multiply directly with beuracracy bonus, and then with science/market bonus.
Relevant factors:
- hammer cost (with/without stone; protective; have walls already)
- ETA to economics
- Capital in Beuracracy?
- Trade route modifiers (look at the city before building castle - what are the value of trade routes there currently? A new route would be worth the same or 1 less than the worst one currently there)
- science / money modifiers
- Other build options (don't simply compare to building wealth; is a resource-assisted wonder available for fail gold? Are you gearing for war and would otherwise build units? Any other special consideration?)
First let's assume a city getting 2 commerce trade routes, with just a library, economics estimated in 20 turns, no wonders available for failgold, and some mild potential to build units instead.
Result: 150 hammers (walls + castle) / 3 for protective = 50 hammers for 2.5 beakers exactly "pays off" compared to building research in the 20 turns until economics arrives.
You should be aware, that this actually doesnt make the building worth it, for 2 reasons: (1) building research now instead of a castle, gets you those beakers sooner. A handful of cities building research might easily get you a key tech 1 or 2 turns sooner, vs a delayed 'same' benefit from castle (2) 50 hammers into a unit (or focussing food before whipping an army after a new military tech arrives) will likely pay off a lot more than either building wealth or other 'economic' building like a castle. Imagine 5 cities building 5 catapults instead of research - could easily accelerate a city's capture, or a whole war, by a turn or more.
Next let's assume a healthy but realistic case where the castle might work out: a capital with beauracracy and at plenty of extra foreign, intercontinental trade routes, and a library and academy. Assume also that wonders are available in stone to build instead, and that that a friendly AI is 15 turns away from economics, which you would be able to trade for.
Result: 150 total wall + castle hammers, divided by 350% for stone, protective, and beuracracy bonus = 43 hammer, which gets you, say, 4 base commerce * 1.5 beuracracy bonus * 175% science rate = 10.5 beakers per turn * 15 turns until econ = 157 beakers at a cost of 43 hammers. Compare that with 64 research, (50% beuracracy bonus), and it looks almost reasonable (though not guaranteed!). Compare it with a stone wonder for fail gold, and you get 43 * 250% = 107 gold, and it gets very questionable again, even before considering building units instead.
Lastly, let's assume a behemoth capital on the coast with harbour, as well as library, university, academy, and Oxford.
You might be looking at 9 coin base trade route, * 1.5 beureau bonus * 300% science rate = 41 science per turn, wow! Even 3 turns until econ would earn you 123 beakers, compared with the 43 hammer cost, (which we know from above is about the same as the 107 gold you could get from a resource-doubled wonder, instead).
But... at that point, with a capital like that, how far away from econ could you really be? Would it even take 5 turns for you to research it on your own (which would be quite tempting if the great merchant is in reach!)? Maybe you say you rushed engineering for a treb rush... but then dont you need to be pumping trebs and maces, instead?
Conclusion - the better the economic impact of the castle, the shorter window of time to payoff, with payoff from trade routes alone being... probably (almost) always questionable.