The police had responded to an “active threat” at UPMC Memorial hospital in York County, Pa., where a hospital official said the gunman had been apprehended.