Is it unethical to get paid for the work and time invested in thesis?
That is totally fine, many people do a master thesis in an official cooperation with a company. University hasn't hired you for your studies, and the diploma is not your "payment".

Who might be in trouble is your professor and his company, if he hasn't cleared this with the university officials. Because he has a contract with the university, and they have some rights to your results, because they provided the lab, provided your professor, etc.