The purpose of patent is to encourage innovation. If companies/individuals didn't have protection for their invention, why would they invest into R&D if their competitors could steal their idea/process?
It provides a middle-ground - the inventor has exclusive rights to the invention for a portion of time (20 years), where they can reap the benefits of the patent. Once it expires, anyone can use it.