The tradition of placing anything at all on a grave (let alone flowers) goes back as far as the practice of burying the dead, whether that be inhumation or cremation of a whole body. In ancient times, it was common to burn the body and then place the fragments in an urn or pot. (Cremation urn.) At some point mankind realised it was practical to place a corpse beneath the ground as it was not good to leave them lying around. This may have happened as humans ceased to be so nomadic and so needed reasonably healthy surroundings in which to raise their more settled families. Some cultures took the dead to the tops of summits and left them out in the open for the predatory birds. For those who chose to bury their dead under the ground, some form of 'weighting-down' was often necessary to protect the remains from wind, other elements and predators. Often, heavy objects such as piles of stones were placed over the 'grave' which in some cultures developed into a mark of respect where every passing person would add a new stone. It is not a big leap to see how that might stretch to flowers.
To say that this tradition goes back "centuries" is to understate things a great deal. The tradition started long before that and it started long before coffins.
There is some dispute about what archaeological finds really prove that flowers were intentionally placed with dead people in graves (as opposed to having rodents or something bring it in). However, it is pretty well accepted that flowers have been found in a grave as long ago as 4,000 years before the present. (There is at least one Neanderthal burial site in Iraq where some archaeologists say flowers were placed in the grave -- this is from really long ago since Neanderthals died out around 30,000 years ago.)
Because the tradition started so long ago, there is no way to know why the people did this. A common explanation is that flowers signify the start of life. So putting flowers on a dead person would imply a hope that they would start a new life after death.
The tradition of laying flowers on top of the coffin started centuries ago. When people died flowers were brought in to lie around the bodies to help prevent the smell of the decaying body. It was traditional in some cultures to keep the person on display in the home for several days. The body would start to decay and omit a strong and unpleasant odor. As time passed and bodies started to be embalmed, the flowers continued. Eventually they were placed on the top of the coffin.
Flowers signify the final gift given to the dead. They also serve as a sign of respect. I once attended a funeral where the man had a spray made up of tobacco. He had spent his whole life as a tobacco farmer. Coffin sprays of today have evolved to include things such as personal items instead of flowers.