Companies hoping to sell marijuana for medical use in Massachusetts will be required to hire an independent lab to test their products for contaminants, under final rules that regulators approved by unanimous vote.