Many of the compounds of sulfur have a strong odor. Hydrogen sulfide from rotten eggs, the mercaptans of a skunk, the odor compounds in onions and garlic, the bitter taste of brassicas (cabbage, Brussels sprouts, collard greens, and similar plants) are all sulfur compounds. What is it about sulfur that makes this so common?
Nice question! It would, obviously, be a long answer if I talk about all types of sulfur compounds here. So I will take up just 2 examples to explain this.
Thiols: when we talk about sulfur compounds with foul smell, thiols (mostly) come to the top in the list. Thiols (R-SH) are a class of compounds famous for their smell. Some examples of thiols include:
Some biologically important examples would include coenzyme-A, glutathione and cysteine. However, not all thiols have fowl smell. For example, furan-2-ylmethanethiol provides the aroma of roasted coffee while grapefruit mercaptan gives grapefruit its characteristic scent. You can see a complete list here.
After seeing some examples, lets come to the main point i.e. why thiols have such foul smell. Thiols are decomposition products of proteins. When amino acids, like cysteine and methionine, are decomposed, thiols are one of the last things to form. This would explain why it becomes important to smell and avoid them (you wouldn't want to eat a dead and decaying mammoth, and a blind hunter might not be able to tell if he has found a decaying mammoth if he can't smell such compounds). As a side note, this also explains why organic acids have sour taste and smell. Compounds like glucuronic acid, citric acid, oxalic acid, lactic acid, butyric acid, acetic acid, etc. are all decomposition products (if you know how vinegar is made traditionally). This is why your body tries to get rid of them (I saw that in a video, if you eat things with foul smell and sour taste (it was a Japanese dish probably), you'll suffer nausea and vomiting since your body will do all it can to prevent its harmful effects). See this Wikipedia page for more info.
- Hydrogen Sulfide: H2S, or hydrogen sulfide, is another compounds famous for its smell. It smells like rotten eggs, and indeed it is because H2S is what rotten eggs release. The basic reason why H2S smells so bad is again the same. Hydrogen sulfide is one of the final products of proteolysis during decomposition (see same Wikipedia article). But there is another cause why H2S has such foul smell (and why I didn't just stop at thiols): H2S is itself toxic.
H2S has many biological signalling functions, similar to NO and CO. These include:
H2S serves as endotheium-derived relaxing factor (EDRF) and endothelium-derived hyperpolarizing factor (EDHF). In short, it acts as smooth muscle relaxant and vasodilator. It also increases the response of NMDA receptor and facilitates long term potentiation in the brain.
it is converted to sulfite by thiosulfate reductase, and further to thiosulfate and sulfate by sulfite reductase, in the mitochondria. Sulfate is excreted in the urine.
it acts on ATP-sensitive potassium channels in smooth muscles, and does the blood vessel-relaxing work in smaller blood vessels.
it blunts, reverses and promotes healing of diverse inflammatory reactions. A full list is available on this Wikipedia page.
the most pronounced effect of H2S is much similar to that of CO. It also binds to the iron in the mitochondrial cytochrome c oxidase and other mitochondrial cytochrome enzymes, thus preventing cellular respiration and causing death.
This would explain why external source of H2S would be so harmful since, being biologically such an active molecule, its amount needs to be controlled strictly. Now, if you want to know why decaying bodies would be dangerous, this Wikipedia article would be a good starting point.
EDIT: The bitter taste of some vegetables is because of a type of compounds called glucosinolates found in some plants. These compounds dissociate upon eating to form isothiocyanate and are thought to be a part of the plants' defense system (see this answer for more details). Interestingly, a similar type of compound, cucurbitacin, found in Cucurbitacae plants, does not contain sulfur, yet it is responsible for the bitter taste of these plants.