Because there's a bit of a pause between "D" and "oh". The apostrophe represents that gap.
Mimic Homer's annoyed grunt to yourself slowly and with exaggerated motions. You'll immediately notice your tongue rising to your palate and your head moving backwards on your neck.
Now, your tongue ricochets off your palate, producing the flat, loud, toneless "D" sound; and at the same moment your head starts moving forwards, faster than it had moved backwards. When your neck is at its greatest extent, air will whoosh up out of your lungs, past your now U-shaped tongue and through your now O-shaped lips, producing the "oh".
There, did you feel that? That brief period after you'd said "D", but before you said "oh!", and your head was rushing forward on your neck, while you weren't making any sounds at all?
That was you, pronouncing " ' ".
Now sing "Doh-re-me-fah-so-lah-ti-doh", and concentrate on your process of producing those "dohs" -- the ones without apostrophes -- and note that in contrast to "d'oh", the sung "d" is tonal: you're engaging your vocal cords and exhaling the entire time, as opposed to in "d'oh" where the air comes out of your mouth all at once, at the end, in a great gust.