A Montana federal judge on Thursday tore into a contested state law that bans TikTok from all personal devices, saying in a hearing that the legislation appears driven by “paternalistic” views of social media users and suggesting lawmakers could have taken many steps short of an attempted ban to achieve their goals.