A diatomic molecule can rotate about two perpendicular axes passing through the center of mass and perpendicular to the internuclear axis.
It cannot rotate about the internuclear axis as the moment of inertia is very small (negligible).
Hence, diatomic molecules have 2 rotational degrees of freedom.