Making even vaguely consistently-repeatable injection molded parts at home is hard work.

The injection molding of a Lego brick is spooky-consistent and very precise. Bricks made 40 years ago work the same as bricks made today do.

Besides that: Cost. Maybe I need 200 1x4 bricks for some project. In the best case, I can spend days or weeks getting the process just-so and eventually smoosh out 200 good-enough bricks (all of the same color) at the cost of all that time, equipment, and some ABS pellets.

Or: 1x4 bricks are sold at $0.15 each from Lego, in any of 40 different colors. So I can just skip all of that work and buy 200 perfect bricks in whatever mixture of colors I want for $30. If I need other bricks for my project, as well, then I don't have to retool for that -- I can just add them to the order.