Organic matter is the final stage of what were once living organisms such as plants, leaves, animal manure and grass clippings.
Organic matter helps because it gives plants nutrients and improves the state of the soil, which in turn helps plants grow better.
Clay soils have tiny particles which means they can easily become one big mass of either waterlogged or baked soil which stops nutrients and air reaching plant roots. Therefore, adding organic matter to clay soil helps stop the tiny clay particles sticking together so that soil then drains more easily, and plant roots can grow.
On the other hand, sandy soil has large particles which means water drains away too fast before roots can access water flowing through the sand particles. In this case, adding organic matter helps those larger particles hold together to keep more water and nutrients available for the plant roots to access.