The best way to apply this is via the runtime arguments to the container (custom JVM args specifically) as shown here, e.g.:
docker run ... \
inductiveautomation/ignition:8.1.38 \
-n gateway-name -- -Dignition.license.leased-activation-terminate-sessions-on-shutdown=true
As to when this leased licence session termination occurs, you are correct, it will be invoked at the very start of a graceful shutdown (via SIGTERM). The default stop timeout for a container is usually 10 seconds, and we now provide up to 7.5s by default for the async gateway shutdown tasks (such as this new session termination function). The correct stop timeout will depend on your application, though, you may need to extend it if you observe that the container is not finishing shutdown within the alloted time.. It is unlikely that you'll need to extend to timeout for the leased activation session termination on shutdown, but there is a separate system property (see release notes here) if you need it.
EDIT: It looks like in K8s, the default timeout for graceful shutdown is 30s (versus the default 10s in a standalone Docker Engine).