TL;DR - this is explained by:
1. Sociopathic corporate philosophies
2. Risk-mitigation against lack of competence and/or integrity of the parties involved in the transaction (HR, low-level manager, employee).

My initial response to this was cynical and pithy: if corporations were people, they would be sociopaths (in far larger proportions than the actual human population). In this case, they seem to have zero regard for fairness, but rather only how they can use others to maximize the benefit to themselves.

Upon further reflection though, it is more complicated, and there are many factors and actors in play.

There is a misguided but universally accepted belief that corporations' supreme obligation is to maximize shareholder returns, and that it would be immoral to NOT take any lawful action that would increase profits. The net effect of this is equivalent to having a single sociopathic business owner who will do anything to maximize their own profits without regard for fairness except when a deficit of fairness begins to negatively impact this end. The effects of this philosophy impact decision makers directly and indirectly throughout the organization, and this phenomenon is one of the results. Being fair or rational in treatment of employees is not mandatory or even the primary driver of decisions.

One way this manifests itself is that management justifies its large salaries and bonuses by minimizing costs, of which employees are often a significant portion. Thus, incentive structures throughout the organization will likely reflect this. It doesn't hurt that executives are likely to be sociopaths to some degree, and this just helps them justify their natural inclinations.

Even in a hypothetical case where all levels of decision makers in a company are benevolent and fair minded, there still remains the difficult problem of determining fair salaries for each employee. Developers aren't truly fungible, but they are difficult to value (especially by those further removed from that role). So, in a sense it is rational to treat them as fungible unless you have a reliably accurate means of differentiating. If an HR person is 100% certain they don't know what is fair outside of averages, it would be a rational decision to let an employee's market price be determined by a public auction process among other companies (aka job hopping), rather than granting a request for a large raise outside the normal range.

Of course, this end could be mostly satisfied merely by matching an offer made by another company (aka job shopping) without requiring the employee to leave and return later. However, that is a very low-friction and low-risk proposition for the employee compared to an actual job hop, so inevitably would see much larger participation if accommodated universally. As HR has no way of knowing what the market rate is for all of its employees, it would also have no way of knowing how much this policy would increase the company's costs if it implemented it and every employee utilized it. If a worst-case scenario would cause substantial destruction profits, this would be a high-risk change to implement, and likely would need other coordinated actions to ensure acceptable long-term profitability and approval from shareholders.

Additionally, there is the risk that the employee had no desire to actually accept the other offer, or even colluded to be given a non-genuine offer (from a friend, for instance) under the condition they had zero intention of accepting the offer. Only once the employee terminates employment and spends a substantial amount of time at another company have they proven the offer was genuine, and that their previous salary truly wasn't sufficient to keep them. That is, without a high level of trust in the employee regarding the offer. It also helps if a trusted party (manager, co-workers, etc) confirms their exceptional value to the company, both in justifying the raise and in indicating there won't be cascading impacts upon the rest of employee salaries.

Diverting from this policy requires additional risk and lower profits, mitigated only by a high degree of integrity and competency in all involved in evaluating fair compensation and the long term cost/benefit of granting a raise vs. hiring someone else. The larger the organization, the less likely it would be a rational decision for upper management to assume this to be the norm. Integrity and competency are impossible to objectively quantify or measure, so for those who manage by metrics, I can see how this would pose a problem.