It’s down to aero, as Newey and McLaren showed in 1998 (where they lapped the entire field in Australia), a longer car works better aerodynamically. Modern F1 cars have a giant spacer in between the engine and gearbox (or more accurately, the gearbox is 60+% spacer) to increase their length.