To put it mildly, it is the economic principle of law at work.
Patents are intangible property, which will not be destroyed like seats, and will exist forever without being destroyed. If you don't set a fixed number of years, many technologies can't be used for free now. The market will always be monopolized, which is unfavorable to the progress and development of society, individuals and countries.
Therefore, it is necessary to set a certain number of years, which not only protects the rights of inventors, but also facilitates the disclosure and wide use of technology.