A Massachusetts judge has ordered Facebook to turn over data about thousands of apps that may have mishandled its users’ personal information, rejecting the tech giant’s earlier attempt to withhold the evidence from state officials investigating its privacy practices.