The California legislation comes amid growing concerns about the impact of cellphones and social media on adolescents’ mental health.