Here in the UK, there are tax incentives to encourage companies to develop new technology, patent it, and incorporate it into products. It's referred to as 'patent box', and can be well worthwhile if you're expecting to profit from technology you've invented. Other countries may have similar schemes to try and encourage investment in R&D.
Also, it's often the stated mission of a small company to get itself in a position to be bought by a larger one. The goal, of course, is to increase the value of the company as far as possible, and having a patent on key technology can help achieve that goal. Even if the small company doesn't have the means to enforce it against infringers, a bigger one certainly does, and so patented technology can have greater value than the same technology without patent protection.