Look at the sentence below. Why do we use the direct object pronoun lo to replace - helado- ice cream.

Yo compro el helado.

Yo lo compro.

There are two reasons. Think of feminine, masculine, singular, plural.
Chart: Direct Object Pronouns lo - it (m), los - them (m), la - it (f), las - them (f)

Now, is my answer correct? And in the first sentence is it masculine singular noun or masculine noun? My answer: Due to the fact that "helado" is a masculine singular noun and must be substituted with a masculine singular pronoun, "Lo" is used.

Because "helado" is the direct object of the sentence and undergoes the action of the verb "compro," "lo" is also used (I buy). Hence, in order to prevent duplication and make the phrase shorter, we must use a direct object pronoun. As we are addressing to a male singular noun here, the pronoun "lo" should be used.

Yes, your answer is correct. "Helado" is a masculine singular noun, so it must be replaced by a masculine singular pronoun, which is "lo." Additionally, since "helado" is the direct object of the sentence, the direct object pronoun "lo" is needed to avoid repetition and make the sentence shorter.