Quick answer: Dogs roll in the grass to coat themselves in a new scent — a behavior inherited from wild ancestors who masked their smell before hunting, combined with what appears to be genuine physical enjoyment.
Wild canines roll in strong-smelling materials to mask their own scent before approaching prey. Domestic dogs retain this instinct and apply it to anything with an interesting smell — fresh grass, dead animals, other animals' markings. The stronger the smell, the more attractive it is to roll in.
Dogs communicate through scent. Rolling in a smell may be a way of collecting information to share with other dogs — announcing where they've been or what they found. It functions similarly to a social update in canine communication.
Beyond instinct, rolling in grass often looks like pure enjoyment — wriggling, relaxed body language, happy behavior before and after. Some dogs roll in freshly cut or wet grass simply because the texture and temperature feel good on their back and sides.
Rolling in grass is driven by scent instinct and physical enjoyment. The only real concern is if what they're rolling in is toxic or chemically treated — check what's in the grass they favor.