There are a number of reasons for the fuel limit.
One is simply that the engine manufacturers want efficiency to be a relevant factor, because it aids in their R&D and marketing efforts. With a fuel limit in place, F1 becomes a showcase for both performance and efficiency.
Another vital reason is to limit speed and cost. Back in the 1980s, F1 was in the midst of a turbocharger-driven arms race. Manufacturers were adding more and more boost, which had a severe impact on both costs and safety. The high levels of boost severely stressed the engines, so teams were replacing the entire engine after a single race. Many teams were using "qualifying special" engines that were built with a lifespan of just five laps. The extra power was creating dangerously high speeds and the effects of turbo lag made the power delivery of these engines very erratic and difficult to control.
Many other racing formulas use a restrictor plate - a metal flange with a hole of a specified diameter that restricts the air intake of the engine, creating a hard limit on maximum power.