Android apps are still heavily based on Java. But doing Java stuff at runtime has proven to be fairly slow still.
So modern Android does something called Ahead of Time compiling (AOT) where it compiles the Java bytecode to native code at installation.
After an OTA, those are all invalidated because system libraries may have changed, so it needs to redo that. That's what it's doing.
If you adb shell into the device while it's doing that, you'll see it's running dex2aot on all your apps.
Yes it'll do it if you flash it directly too. For the update process purposes, there's very little difference between regular OTAs and flashes in recovery. You just don't see it on first boot because you're busy doing the initial setup screens and system apps are usually precompiled and baked into the ROM anyway. No third-party apps installed, no optimization to do.
They could probably just do it in the background silently, but it does give an indication to the user that heavy stuff is going on in the background and thus explains why the device is running a bit slower, a bit hotter and using more battery than normal. A lot of things a regular user could be concerned about immediately after an update, so you're better off letting the user know stuff is happening and that it'll settle down.