The fossils are formed when an organism dies and gets preserved due to some conditions.
Since all living organisms contain a certain amount of carbon in their body when they die and, their fossil is formed the carbon present in the living organisms gets stored in the fossil as well.
An example is the carbon film fossil which is formed due to the carbon residues left behind of soft-bodied organisms after they die.