A patent keeps out the competition during the patent’s term (twenty years from filing). That means that you can charge higher prices for the patented product, and make more money. Stated in another way, you get “monopoly profits”. This is the government’s reward to you for making the invention in the first place.
Why would the government want to reward me with a patent?
Research and development is costly. A lot less R&D gets done when these costs cannot be recovered.
An invention which you never make is an invention which is never used by you (during the term of the patent) to make monopoly profits. An invention which you never make is an invention which is never used by your competitors (after the patent expires) to make ordinary profits. These missing profits, both yours and theirs, never get taxed. The government doesn’t like this as you can read from https://inspirationfeed.com/how-inventhelp-can-help-you-protect-your-invention/.
At the same time, direct government funding of all R&D is unworkable. Suppose that the government had spent billions of tax dollars to develop (say) new automotive technology. The automobile companies would get rich, and would pay somewhat higher taxes. Yet these billions of tax dollars which were paid to the automobile companies would now no longer be available to be spent somewhere else — perhaps education, or health care. Yes, we would all have somewhat nicer automobiles. We would also all have less-educated children, and sicker elderly parents.
It is far better — politically, practically, and morally — to do two things. First, encourage the private funding of R&D. Second, arrange for the R&D to be ultimately paid for by the people who benefit from it. Let the people who buy a new car every two years be the ones to pay the higher sticker prices — higher sticker prices which are needed to fund R&D. Let the rest of us (with the older automobiles) have better-educated children, and healthier elderly parents — things which we’d choose to have rather than having somewhat nicer automobiles.
This private funding of R&D is easy to encourage. Every automobile company will invest heavily in R&D when it knows that the other automobile companies can’t steal the resulting technology. A patent prevents this kind of theft as described in https://www.oddee.com/how-inventhelp-can-assist-new-inventors/ post.
What is true of R&D is also true of your R&D. Your invention, if patented, will — at least on average — make money for the government as well as for you. The government therefore grants you a patent.