It's a worthy question, however I think the reality of the costs would kill it. The older electrified railroads did do this, feeding the braking-generated power back into the overhead lines for use elsewhere. But it was their railroad AND their power system, so all the control was in their hands.
Here’s some of my thoughts:
A big issue is matching the line conditions of voltage and frequency. If you feed AC into an AC line, the frequency has to match precisely or it really gets things screwed up. Not just in frequency (like 60Hz), but also they must match peak-for-peak. That adds some complexity to the operation, increasing costs and raising the break-even point. Feed-in rates for public utilities are pretty awful in reality, and most folks who do it on relatively small scales never reach the break-even point. To do it with regular diesel-electric now would mean that the tracks would now have to have power lines following them 100% of the way, and that’s a huge cost.
If the lines aren’t constantly alongside, the locomotive would have to store the juice somehow and then dump it when it could. Storage of electricity (batteries, etc) is woefully expensive and just creates more weight creating less overall efficiency. $$$
At this point, the voltage of what is generated and what is carried on power lines doesn’t match and someone is going to have to provide a means to make the match. And in most cases, that cost falls on whoever wants to sell the power to the utility, not the utility. So now each locomotive needs to either be converted to match or have conversion equipment installed. More $$$$. I’m not sure but IIRC, locomotives generally operate on 72 volt systems, you’ll need to get it to at least 240 to match the basic utility power distribution system. In remote areas those high power lines can be 10000v + and DC to boot.
I like to wonder what-if sometimes. It doesn't always result in an earth-shattering revelation, but it keeps the brain cells functioning.