Phone looks small but it has some expensive parts like OLED displays, sensors, and miniaturization of things in phones to absurd levels do add to overall cost as oppose to savings.
The mac mini computer on the other hand has nothing critical inside, plenty of space to do things comfortably. The secret sauce is the apple silicon, which is developed by ARM and manufactured by TSMC, apple being long time customer of ARM, they have special privileges in the industry, as an example the cost at which they can get things manufactured is very hard for competitors to match, how much they sell it for is a different issue.
They will always stay ahead in the nanometer race.