That, but not only that. Attacking has the intrinsic advantage of choosing when, how and where to strike. Due to how buffing etc. work, and due to the many ways in which an 'attack' in whatever sense of the word can be conducted, this is a huge attacker's advantage. Sure, if the objective is to take/keep a specific place or item, the "where" is covered. But in D&D, it simply binds up so many resources to defend against every possible avenue of attack, that the attacker has a fat chance of choosing a workable method of attack.
Just fortifying a place against teleportation and divination is extremely complicated and costly, while the corresponding methods of attack are comparatively cheap. Getting a place made out of unbreachable material is likewise nigh impossible. Traps are very expensive. Etc. And each of those only cover one thing you have to guard against.
A quick, well-prepared one-shot takedown is hard to defend against in D&D - and this holds true regardless of the dimensions you're looking at: tactical (e.g., trying to protect the BBEG in an encounter) or strategic (e.g., trying to protect a castle vs. attack).
EDIT: I'm not sure where this discussion is going; it certainly leaves the topic of this thread. If you don't like it here, say so, and I'll leave off.