That's a great question!
As a native French speaker, I actually never thought about it and I guess I just learned all of the special cases by heart without noticing. However, from your perspective, I can totally understand that it seems a bit confusing.
I don't have any formal answer to offer you, but I can maybe give you a good heuristic to help you understand in which situations you should use each type of expressions.
Here we go:
The expressions beaucoup de..
, énormément de..
or un peu de..
are used for the times you would say a lot of..
, a bit of..
, tons of..
in English.
However, de
can become du
or des
when, in English, you would use the
instead of of
, like in beside the cat
-> à côté du chat
.
So as a rule of thumb, in a lot of contexts, of
= de
, and "de"
becomes invariant, but every time you use "the"
, to translate in French, your de
can become de
, du
, des
, de la
.
I hope this gives you a bit of intuition about when to use each form.