The defensive aspect is for companies with real products.
Company A owns patents X, Y, Z.
Company B owns patents M, N, O.
Company B sues company A that one of their products infringes on patent N. Company A countersues that 3 products of company B's infringes on X, Y, & Z.
That's the defensive aspect for company A. They won't instigate but they'll retaliate aggressively. This is known as the "nuclear option" as this strategy was employed during the Cold War - build up your offensive arsenal as a defensive measure to protect yourself against a first strike.
Plenty of examples during the smartphone patent wars[1] and perhaps this strategy isn't quite as successful as it once was.
For patent trolls having a large patent portfolio can increase the likelihood that you own a patent that the troll's patent is based on helping you with prior art claims. So having a large patent portfolio improves your defensiveness there. Additionally a large patent portfolio increases the value of your company because those patents are IP that have tangible value in the market; many tech companies choose not to monetize but frequently IP licenses can be bought/sold (or even the patents transferred) and mutual IP licensing is frequently part of lawsuit settlements so there's further value there. Since it's impossible to actually predict the value of almost any given patent in the future, having a large war chest improves your bargaining position/value of the patent portfolio.
[1] https://en.wikipedia.org/wiki/Smartphone_patent_wars