The early carboniferous was warm with lots of tropical rainforests. When the trees died the carbon was trapped within the swampy environment. Carbon was buried without oxygen.
During the cretaceouscoal is found in Spitsbergen where rock types are dominated by limestone chalk with lots of ocean spreading.