The reason why drain water smells foul are as follows:
1) Various gases build up in the drain that produces odour.
2) Drains have sewage material. Various bacteria act on sewage material and produce foul smell. Also bacteria acts on sulfates present in drain water and produce hydrogen sulfide gas which produce smell of rotten eggs.