The ruling follows a lawsuit from Maine Attorney General Aaron Frey and a coalition of other states.