The sound a cow makes is "moo". The word "moo" can be found in "mood". When someone or something is "in the mood" it means they feel like doing something. This joke is playing on the word "mood" because it has "moo" in it which references the sound a cow makes. 
Cows make noise only when they ' re in the mood .