Garry's Mod itself, bought through Steam, does not install malware. If something on your machine picked up a virus, the far more likely culprit is a third-party download: a mod, addon or "installer" grabbed from a random website rather than the Steam Workshop.
That is the pattern to watch for. Files pulled from unofficial mirrors are a common way people bundle unwanted software with a game download. Stick to the Workshop and official sources, run a reputable antivirus scan, and avoid any site offering "free" copies of paid games, which is where most of these infections actually come from.