Basically this logging is triggered if the CPU scheduler hasn't switched to the process in the given amount of time, and the process doesn't qualify for an exception.
The exceptions are special cases where a process hasn't been switched to but it shouldn't get logged about. I don't clearly understand the conditions for the exceptions; FWIW the comments on the cases in the code are:
Also, skip vfork and any other user process that freezer should skip.
Also, when a freshly created task is scheduled once, changes
its state to TASK_UNINTERRUPTIBLE without having ever been
switched out once, it musn't be checked.
(from check_hung_task() in Linux hung_task.c)
https://elixir.bootlin.com/linux/v5.12.12/source/kernel/hung_task.c#L92
As to why a task might not be scheduled for a long period of time, it being continuously in TASK_UNINTERRUPTABLE ('D' state in top), such as when blocked waiting for I/O to complete, would be one possibility, but I don't know what others there might be.