Does the freshness of the ingredient impact the longevity of the cooked dish?
It Depends.

First off, by 'goes bad' I'm assuming you mean both 'stale and unpalatable' and 'moldy and not food-safe'. And for both of those, it's going to greatly depend on what ingredient, what you're making, and how you're making it.

In the case of tomatoes, if you take your batch of 'last-legs' tomatoes (and I'm assuming you mean there's almost an unsafe level of bacterial/mold growth on them), and thoroughly cook them into a sauce, i.e. bring to a boil for an extended amount of time, you'll (hopefully) kill of the microbes, and inactivate the toxins created by those bacteria, you will have a generally safe-to-eat sauce. Compared with a similarly cooked sauce from fresher tomatoes, it will probably get moldy at roughly the same average rate. 

However, it will probably taste worse. The 'last-legs' sauce will get to unpalatable faster than the fresh one. 

Generally, if you're able to cook something thoroughly, you'll generally 'reset' the microbe growth timeline back to the starting-point. 

With meat, however, you usually don't want to cook it to the point of sterility. (If you don't believe me, boil a steak for an hour. Then try to eat it.) So if you have a last-legs steak, I wouldn't cook it, then store it for a week in the fridge. Making a stew might be a good move, however.