It comes from grins translating to “grinning”. My generation grew up with ICQ which had smileys. This thing with writing g was more common in online communities like online games and chatrooms and was more an internet subculture thing than mainstream knowledge along my peers.