You work for a company for X amount of time, and you gain domain knowledge of the company, and general industry experience. Some other company looks at your CV, and without knowing you, and probably without caring about your specific company domain knowledge, decides you are worth say 20% more than you are earning. You then go to your current company, and say 'my general skills are worth 20% more on the market, you know how well I work, and you know I have extra domain knowledge specific to this role, I would like more money' - and the company refuses.
They then spend time and money finding someone with similar skills to what you have, but without your domain knowledge, and probably at a similar amount you asked for since that's the market rate.
How is it not in the companies best interests to just keep you on and give you a raise? How do they justify all that wasted time and money every time? Do they just not measure it?