Massachusetts district attorneys, public defenders and a community group filed a lawsuit in federal court Monday against U.S. Immigration and Customs Enforcement to prevent the agency from arresting and detaining immigrants at courthouses in the state.