Boiling point of a covalent (molecular) substance is dependent on the strength of the intermolecular bonds. The stronger the intermolecular bonds, the more energy needed to overcome them and thus the higher the boiling point.
Such intermolecular bond depends on two main type of interaction: tempory-dipole-temporary-dipole interaction and permanent-dipole-permanent-dipole interaction.
The strength of the former depends on the size of the molecular electron cloud. The more electrons the molecule contain, the stronger is this type of intermolecular interaction. One can note that the heavier the molecular weight, the higher the number of electrons present and thus the higher the strength of this particular intermolecular interaction.
The strength of the later would depends on the electronegativity difference in the polar bond present in the molecule, and thus the strength of this form of interaction. Generally, polar compounds would have higer boiling point than covalent compounds of the same molecular weight (eg. NH3 is liquid while CH4 is gas at stp.)
These two factors would contribute together to the overall strength of intermolecular bonding. Since temporary-dipole-temporary-dipole is not the only form of interaction and it isnt the most dominant form of intermolecular interaction for all cases, molecular weight would thus not be a reliable predictor for boiling point for all molecular substances.
In the case of halogens, they possess similar structure and intermolecular bonding. Futhurmore, the dominant form form of intermolecular interaction is temporaryd-dipole-temporary-dipole interaction. Hence. molecular weight is a good predictor for the boiling point of halogens.