The way maggots get into coffins when in the ground is that the maggots are laid in the soil when it rains.
Basically maggots are fly eggs or baby flies that eventually turn into flies.
The mother fly lays the eggs or maggots in the soil where the coffin is and then the maggots work their way down into the soil.
Eventually the maggot gets deep enough into the soil where they get to the coffin.
As a coffin is in the ground the coffin starts to rot and the seals rot as well.
The maggots are then easily able to get into the coffin through the rotted seals and also the rotted coffin.
A coffin will eventually years down the road rot out and make it easier for maggots and other insects to get into the coffin.