When you add rennet or acid to milk, it separates into two things: a solid curd of casein protein and fat, and a watery yellow-green liquid called whey. Lactose is a sugar, and sugar is water-soluble — so it stays dissolved in the whey. It does not travel with the curd.
Cheesemaking is, from a FODMAP perspective, essentially a lactose-removal process. Every step that drains, presses or drives off whey takes lactose out of the finished cheese. That is the first mechanism, and it does most of the work.
The second mechanism is ageing. Whatever lactose remains trapped in the curd becomes food for the bacteria in the cheese, which ferment it into lactic acid over weeks and months. This is why a cheese's sharpness and its safety rise together: the tang of a mature cheddar is the by-product of the lactose being eaten. By the time a hard cheese has aged a few months, its lactose is essentially gone.
The more whey removed and the longer aged, the lower the lactose. Hard, dry, sharp, old → safe. Soft, wet, fresh, mild → higher lactose. Nearly every cheese you will encounter follows this, and the apparent exceptions turn out to confirm it.