In Gnus it's called "splitting" the mail. It's covered in section 6.4.3 of the Gnus manual. (run M-: (info "(gnus)Splitting Mail")
to jump right to it. Here's an example from the manual:
(setq nnmail-split-methods
'(("mail.junk" "^From:.*Lars Ingebrigtsen")
("mail.crazy" "^Subject:.*die\\|^Organization:.*flabby")
("mail.other" "")))
You can see that it takes a list of folders to split into, and regexes to match against.
Since you're using IMAP, however, you want to set the variable nnimap-split-methods
instead. It works the same way, but only applies to IMAP. See section 6.3.3 of the manual for more details.
Also, you might consider setting up filters in the Gmail UI instead, so that email is always sorted correctly even when you're not running Gnus.