Add the package name to DNF’s protected list:
Edit /etc/dnf/dnf.conf.
[main]
installonly_limit=5
protected_packages=kernel-6.17.4-200.fc42.x86_64
The solution from @ilikelinux works because the running kernel will never be removed, so if you always do your updates from that running kernel, it’ll be in use when a new kernel is applied and thus won’t be removed. Of course, if you forget to switch to it… it’s very likely going to be removed as it’ll probably be the oldest.
Addendum : apparently doesn’t work, as nether versionlock or ptoected_packages applies to kernels, despite no mention of this in the man pages. Tread carefully dear reader as what you thought was a sure fire “never remove this thing”… isn’t.