Running Rocky (or likely RHEL) in a VirtualBox, you'll want to install the guest additions. This requires the Linux headers which are not installed by default. So we need to
dnf install kernel-devel kernel-headers
but this is not enough it seems.
See superuser and debugpoint
It seems you have to reboot after installing as above. Nope. Still complains of missing Linux headers.
It seems that dnf is not installing the correct version of Linux headers.
Ok, update the kernel to match the installed headers and reboot.
dnf update kernel