Cap hits do matter because cap money is a significantly more scarce resource (that can't even be replenished in certain cases) than team revenue. NFL teams are obscenely profitable, in part because of the salary cap. That's why team valuations keep rising at absurd rates. How much a team is actually paying in cash for players is not a big deal for the business side, because there is such a gigantic margin after all the operational costs are paid. Basically, there's always more cash available.
However, the salary cap is subject to strict rules and a franchise can very easily put itself in a position where it can't put a contender on the field for a few years because of bad salary-cap decisions. Giving a 35-year-old quarterback a fully guaranteed five-year, $250M contract, for example, could do that.
The Lions could afford to pay Goff a lot more than $26M in cash, even though it would be a terrible investment. They'd have the cash if his 2022 salary and bonuses were twice that. But that $31.5M cap hit is a big, big deal, because it's 14.3% of the team's whole cap for its entire 53-man roster (just the top 51 until the season starts, but at that point, it covers the 53), spent on a single player who just isn't exceptionally good. That harms the team in terms of competitiveness. Not fielding a competitive team can hurt the organization's finances a lot, because on-the-field success is an important driver of team revenues.