What is the meaning of 子 in words like 菓子(과자), 帽子(모자), or 獅子(사자)?
「子」originally meant child. By extension, through the following sequence, it was further used:


To emphasise the smallness of an object.
As a diminutive suffix, conveying a sense of intimacy/endearment.
As a nominal suffix, doubling as a way of transforming a monosyllabic noun to disyllabic.


In the diminutive aspect (Chinese: 指小詞, Korean: 指小辭・지소사), its function is very similar to the examples in the answer given by the question posted here.

In 菓子 and 帽子,「子」may play any one or a combination of the three uses above; the answer is not entirely clear, as the uses are related to one-another. In 獅子,  which is obviously not small,「子」is used in sense 3 above and should be seen as the same as —이 in Korean 虎狼이.



Note, non-Mandarin Chinese languages also use diminutives; Cantonese「仔」is cognate to Mandarin「子」.