Why boil and cool jam before using it in a cake?
This step is not about food safety, it's about consistency and in fact about three properties of your jam: Jam comes in a wide variation of consistencies, one parameter is "stiffness", another "water content" and a third "smoothness".

In baking, you want smooth (no lumps) jam that is speadable enough to form a thin layer (especially if used as a "glue"), yet thick enough not to "bleed" into your baked layers.

What you basically do is play with the pectin in your jam - a warm pectin solution (aka jam) is soft, cold pectin solution is solid, softening goes quickly, re-solidification takes some time. But enough "kitchen chemistry", here's the practical approach:


Warming your jam makes it liquid enough to be easily spreadable and, if necessary, to strain out any lumps of fruit. Sometimes a good stir can give similar results, but stirred jam won't solidify again afterwards.
Boiling the jam lets water evaporate, thus thickening or "hardening" the jam (once it solidifies again). This can be advisable if you have a rather thin or soft ("watery") jam in the beginning. Especially under marzipan you want no excess liquid in the jam to avoid softening the marzipan layer or cause it to slip. The boiling is optional, it needs some experience to determine whether it's really necessary for the specific brand of jam and the specific use.
Cooling down the jam again has two reasons: Not all baked goods take well to being drenched with hot liquid and the possible thickness of a layer is partly determined by the consistency of the jam. Especially sponges etc. tend to soak up liquid jam, resulting in a coloured stripe of dough instead of a distinct layer of jam. (Note that there is also the technique of brushing hot baked goods like danishes with hot apricot jam for a glossy sheen, but that's not what we are talking about here) But you also don't want to wait until the pectin has solidified the jam again, because then you would be back to square one. Depending on the intended use, you let the jam cool until it has reached the desired consistency - still rather liquid under marzipan (as it will solidify on the cake quickly) or almost solid but easily spreadable for a distinct layer in your sponge that still can hold the cake layers together. Note that most recipes say "cool" but not "cool completely".