The purpose of granting patents historically was to incentivize innovators to bring their knowledge into the public domain in exchange for a monopoly for a certain period of time. Before patents, there was a disincentive to sharing your knowledge as others would free ride on it so inventors would just sell their products on their own and their knowledge would likely die with them. Imagine you developed penicillin but there were no patents. You just sell it and never tell anyone how you created it.