Dogs scratch their beds before laying down to rearrange their bedding to provide for more comfort during sleep. This behavior is not unlike that of humans, who may fluff up their pillows before turning in for the night.
Another reason why dogs exhibit this behavior is that they are trying to dig themselves a den in which to hide. As seen in the wild when dogs circle in an attempt to flatten grasses.
Scratching their beds can also be a dog's primitive response at achieving a more comfortable temperature, either a warmer temperature by eliminating cold snow or a cooler temperature by digging down to reach a cooler part of the Earth.