Two conditions for galaxy quenching: compact centres and massive haloes