Trees are a near perfectly designed piece of engineering, allowing simultaneous strength and flexibility.
Five hundred million years ago, the creation of lignin was an important component in allowing plants to move from an aquatic habitat to a land based ecosystem. Lignin gives land plants their rigidity. It took millenia for fungi to evolve to a point where they could decay lignin, so back in the Cambrian period trees never decomposed.
The cell structure found in trees is made up of a matrix of tiny microfibrils, consisting of cellulose (allowing flexibility) and lignin (supplying strength). Through a process of tensile forces, the tree is prevented from collapsing under its own weight or snapping in a strong wind. If a tree is in a very exposed location, the structure of the matrix will adapt to create further protection.
If you are interested in reading more:
https://agroforestry.org/the-overstory/128-144-how-trees-stand-up
Illustration from the V&A Collection - Artist: Johann Bernard Klombeck