Eventually, though, once a company gets large enough, it needs to diversify in order for it to not be totally dependent on one revenue stream, lest it find that stream disrupted in the future. Apple used to be strictly a personal computer company; now it sells not only computers, but it sells smartphones, tablets, headphones, smartwatches, and other consumer electronics, as well as provides services for a fee. Google has a lot of activities, and Facebook has been branching out into VR through its Oculus acquisition.
Having a research lab could be helpful with exploring other areas that the company could branch out into.
I say that tongue-in-cheek, but only partly. There actually is a ton of research that goes into following things like cultural trends and human psychology to ensure maximum ad consumption. Advertising in the middle of a mobile game or on Netflix requires an entirely different school of thought than advertising on traditional cable TV or news websites.
A notable “innovation” (though many may not respect it very much) is the new paradigm of advertising stuff via Instagram influencers and the functionality built into the app to facilitate it. Someone had to research and design that, just like such companies now are probably trying to find the best way to advertise in VR/AR platforms or in rideshares.
To research new infrastructure technology to reduce expenses or simplify operations (making outages less likely, feature development easier, etc.)
To get better at targeting ads by investing in data science/machine learning/AI
To create new products through which to serve ads, reduce CAC, or build goodwill or diversify
To generate publicity and press for recruiting purposes, public perception, etc.
To acquire patents or to genuinely just try something new and figure out how to use it later
Even disregarding the product reasons, research often makes these companies look good to both a technical audience and sometimes to politicians who value "innovation".
They could stop working on their products but they wouldn't last long. The consumer tech world changes rapidly and is fiercely competitive.