Compositing is the last rendering stage. The browser keeps parts of the page as separately rasterized layers (GPU textures) and combines them into each frame, applying each layer's transform, opacity and clip as it draws. In Chromium a compositor thread does this from property trees and display lists the main thread committed; in Firefox, WebRender renders it, in a separate GPU process on platforms that use one. No spec defines layers: when an element gets one is engine behaviour.
transform and opacity are cheap because neither changes layout or the element's painted content. A transform moves the painted result, not the box, so nothing else reflows. On its own layer, a new frame is the same texture drawn at a new position or alpha. The compositor can then run a declarative animation (CSS, transitions, element.animate()) by itself, frame after frame, even while the main thread is busy. Firefox's DevTools mark such animations with a lightning bolt.
Other properties cost more. Animating width, margin-left, left or top reruns layout and paint every frame; background-color usually repaints. All of them need the main thread for every frame, so a long task freezes them.
When an element gets a layer is engine behaviour too. Chrome promotes an element while a transform or opacity animation is running, and for will-change: transform or opacity ahead of time. Each layer costs GPU memory and texture uploads, so promoting everything backfires.
A stacking context is not a layer. Stacking contexts group paint order and are defined by CSS; opacity: 0.5 and z-index: 1 each create one, yet in Chrome 156 neither got its own composited layer. Layers are how an engine caches and moves pixels.