There are gases in your pipes that smell disgusting and are harmful to your health. They are called sewer gases, and it is important that you keep them out of your home. The problem is that gases usually rise, which means that they would make it right in if there was nothing to hold them back. This is why there is a p-trap on every pipe that is connected to the sewer. You probably have seen the curved pipe under your sink, and it’s fairly obvious how the toilet is shaped in a similar manner. This is why a sink or toilet that goes unused for a long time will start smelling really bad. The p-trap only works if the water level is high enough to cut off any gas from passing through.
Even a dishwasher that is connected to your drain needs to have a p-trap between it and the sewer. Sometimes appliances will connect to a pipe before the p-trap to avoid the need to have a separate p-trap.