This question also has an answer here (in German):
Wieso muss »es« in diesem Satz stehen?
Ich mag es, am Strand zu liegen
The way I see, this phrase could have the same meaning as 'Ich mag am Strand zu liegen', but this apparently isn't the case.
It is an argument of the verb
mag, which functions as a direct object and pronoun for "am Strand liegen".
Perhaps a good analogy to English would be this sentence:
I like it when I can [just] lie on the beach [and do nothing].
Sometimes this word "it" disappears into the mysterious world of consciousness :) (see https://en.wikipedia.org/wiki/Ellipsis_(linguistics) because it is redundant or unique such that "it" can only function in one way. In other words, it can be skipped by the mind (perhaps to save time in speech?)