Actually, in most cases - no, they can't. Or, rather, they can't figure it out as fast as they're "needed" to.
> if there's a real need with no alternative
What happens instead is that somebody with no real knowledge of software development says, "we need this change made in two weeks. We need this." That this might be impossible for any human being, living or dead, is completely ignored. If the programmer this is dumped on even suggests making any clarifying improvements to the code, even that is rejected because "we need" this.
And two weeks come and go, something was changed because there was a deadline, but the something that was changed broke a dozen other things nobody even remembers were there, and now there are bugs waiting to be discovered by unsuspecting users.
> it's a matter of incentives and prioritization
I know what you mean - it is, technically possible but it's never feasible because it's not predictable.