I won't pretend to know exactly what should've been done with their engines but they had a few routes they could've gone down.
If they stuck with Ego (which they've used since the PS3 gen) then they should've upgraded it enough last-gen to handle longer track lengths they might be using in the future. When engine upgrades are done it's common to over-shoot the final requirements eg. we can now handle so many lights, or ray-tracing, or up to 100km² maps, even if realistically they might only utilize a fraction of those features. You can't be fighting against limitations of your own tech and you have to be prepared for the next-gen, because people will be expecting more.
The thing is that Codemasters developers were active on the forums over the years and explained all these limitations back in the late 2010s, so it isn't like they didn't have time to get a solution together within Ego. They also had an ideal candidate to experiment with a new engine - the Dirt Rally spin-off, yet they just used Ego for that again.
And if the switch to Unreal Engine at the time they did was unavoidable, why on Earth did they opt for UE4 and not UE5!? They ended up with the exact same stutter issues, but at least they could've utilized the more advanced features of UE5 to allow the team to visually punch above their weight. First impressions matter and if most people are thinking to themselves "this looks worse than the PS4 game", it's just over. And it wasn't even that it was a cross-gen game! WRC only released on PC, PS5 and Xbox Series consoles...
EDIT:
Here is what Milestone, who have been been making MotoGP games since the PS2 days, are managing to do now on UE5, having made numerous engine switches over the years including to UE4 during the PS4 days:
Their other series, Ride, switched to UE4 for Ride 3. This is Ride 5 on PS5 now, still running on UE4, with 7+ years of experience with the engine under their belt: