An environment-dependent halo mass function as a driver for the early quenching of z > 1.5 cluster galaxies