Hershey has won a case against two marijuana companies after the confectionery giant claimed they sold products that infringed its trademarks.