Your nasal passages include structures called "conchae" which, among other purposes, secrete mucus to capture small and potentially disease-carrying particles from incoming air. [1] It's not a perfect defense, of course, but better to have it than not - and when you breathe through your mouth, you don't get the benefit.
[1] https://en.wikipedia.org/wiki/Nasal_concha#Immunological_rol...