1. When it triggers distress for the target of the humour. This includes indirect delivery, such as when the target is not present. For instance, racist jokes encourage and perpetuate disrespect and create a social atmosphere which permits worse abuses to become more likely.
2. In situations which demand serious attention, such as in court. Though I can imagine some types of jokes would occur, such as unexpected expressions of the absurd, which wouldn't disturb the general need for gravitas.
3. At times of grieving, tragedy or emergency. Exceptions - if such times are painfully prolonged, humour can sometimes act as a leaven to relieve the suffering. It takes a lot of nous and sensitivity to judge this correctly.
It is always stupid, or making fun of someone to make himself look better and he is never funny. His persona is fodder for every comedian because he is so incapable of having any human reaction or knowing how to act around anyone and make them comfortable or happy; unless he is buying them for a favor.
When you have no personality, you cannot make jokes.