Massachusetts cannot bar legal immigrants from a state health care program, according to a ruling issued Thursday by the state’€™s highest court, a decision that edges the state closer to its goal of providing near-universal health care coverage to its residents.