Why does spinach lose its texture when cooked?
Before being cooked, vegetables are like a wall built from tightly filled water balloons.  Each cell has is filled with water (well, technically cytoplasm, but...) which is essentially incompressible.  

One of the components in the cell walls is hemi-cellulose, which dissolves into the water when the vegetable is cooked.  This allows the individual cells to partially deflate, expressing water and making the overall vegetable wilt.

Think a blown up beach ball.  Although the wall is soft and flexible, the air holds it rigid.  Of course, air can be compressed, so a beach ball can be squeezed; but water for all practical purposes is not compressible, so there is no almost no give in the individual plant cells.  

Once the cell walls loose their integrity, however, it is like the beach balls that comprise the plant have sprung a leak.  They loose their shape or rigor, and at the large scale you see wilting or softening.

Note that the presence of acid in the cooking medium can inhibit the dissolving of the hemi-cellulose, and permitting vegetables to better maintain their shape.   This is one reason why, for example, canned vegetables have acid added to the canning liquid (another being that acidity above a certain threshold inhibits the growth of certain dangerous food born pathogens.)