The entire point of patents is to give companies a monopoly for a period of time in exchange for not keeping the information secret. The utility and merits of the system is certainly not without debate, but if you want the answer as to why governments are okay with it, it's probably because it was their idea.