「子」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 (指小辭; 지소사), 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「子」.