The settlement was reached during a California federal trial, averting one of the highest-profile tests yet of allegations that social media companies harmed young users.