It shouldn’t have worked, though. This is the sort of logic that should never be used with the e() helper function. Since e() is a function and you pass it some parameters (2 in this case), these parameters are all evaluated, not depending on the condition. So each parameter you pass to this function must evaluate by itself:
Param 1: $kirby->languages()->isNotEmpty(): this is fine
Param 2: ' lang="' . $kirby->language()->code() . '" dir="' . $kirby->language()->direction() . '" prefix="og: https://ogp.me/ns#"': this will always fail if there is no language object.