I think it’s all to do with one of the things the nose does. Because you’re breathing in through your nose, part of its role is to make sure nothing gets in that isn’t supposed to (things like dust, insects, anything that might hurt us).
I believe your body creates a sticky substance like mucus to try and catch this sort of stuff, to stop it from getting further into your body. It’s similar to why your ears produce wax – so that they can push dirt and things that shouldn’t be in your ear, and get it out of there!
I might be wrong though – Blanka and Emma know lots more about biological stuff than me, so I’ll wait for one of them to tell us more!