Google’s YouTube and Snap Inc. reached agreements to settle the first lawsuit headed to trial over claims that addiction to top social media platforms has disrupted learning and pushed public schools to spend massive sums fighting a mental health crisis, according to court filings.