Ok so the fossils are not dated. The surrounding sediment is, right?
No, you are not quite right, and I think that you are confusing the depositional age of sedimentary rocks with the ages of their components. I will try to explain the matter in detail, starting with the difference between sedimentary and igneous rocks.
Igneous rocks (including volcanic ash beds) are formed by solidification of a magma (molten rock). The age of an igneous rock is the time when the magma solidified; it can be determined directly by radiometric dating (e.g. uranium-lead (U-Pb), 40Ar-39Ar or rubidium-strontium (Rb-Sr) dating) of the rock. Clastic sedimentary rocks (such as shale, sandstone and conglomerate), on the other hand, consist of material eroded from older rock formations.
The geological age of a sedimentary rock (and the fossils that it contains) is the time when it was deposited, for example on the bed of the sea, a lake or a river. This depositional age is, of course, younger than the age of the source rocks that the sediments were derived from. This difference is a matter of the first importance, and it is essential that you understand it. The depositional age can only be determined indirectly, by interpolation, as I shall explain below.
A sedimentary rock formation may contain fragments of igneous rocks or mineral crystals derived from igneous rocks, and the ages of these fragments or minerals can, in principle, be determined by radiometric dating. However, these ages are
not the depositional age of the sedimentary rock, and they are not the age that geologists attribute to the rock. Again, it is important that you understand this distinction.
As Subduction Zone and others have already explained, the depositional age of a sedimentary rock formation and the fossils it contains is determined by interpolation, using the radiometric ages of volcanic rocks (such as ash beds) above and below the sedimentary formation. It should be obvious that the sedimentary rocks of a formation were deposited after the volcanic ash bed below it and before the volcanic ash bed above it. I repeat, again as a matter of the first importance, that a sedimentary formation is not dated from the material of the sediments themselves or from igneous fragments or mineral crystals derived from the source rocks.
The fossils in a sedimentary rock were deposited at the same time as the sediments themselves, and therefore after any underlying ash beds and before any overlying ash beds. The fossils are, of course, younger than igneous material derived from the source rocks of the sedimentary formation, but this is not important. As I have explained, the age of any such inherited igneous material is not used as a measure of the depositional age of the sedimentary rock.
I have tried to explain this as clearly as possible. If you still do not understand how fossils are dated, please say so, and I will try to explain it more clearly.