This question has vexed me for a long time now. Sneezing, of course, is caused by a mild irritation in the nose. So thus it obviously meant to expell this irritant from the nose. But why then do we “spray” saliva as we sneeze? This part of the operation serves no purpose, at least that I am aware of. Furthermore, and rather oddly, what it actually does do is make others susceptible to whatever germs you may have at the time.
It does serve a purpose - to the cold germs. Coughing and sneezing are how they spread themselves to new targets, so they have evolved to be able to trigger that reaction in their hosts.
We only spray saliva if we have our mouth open. If we keep it closed then we just spray snot. So you could say that the spraying of saliva is not by design but just because most people find it socially unacceptable to send gallons of snot flying across the room or into their hands.
The sneeze response presumably evolved in order to clear everything out of the membranes and passages quickly and powerfully, a “take no prisoners” approach with necessarily messy consequences. Viruses then comandeered this delivery mechanism in their evolutionary development.