Crucially, in all but a few languages, whitespace doesn't matter at all. The parser throws it out.
Whitespace is a HUMAN affordance for a HUMAN audience. If you think it looks kinda okay, that's all that's needed. You absolutely cannot do that with code that actually does something.
I suppose, fundamentally, all code is for humans to read; the CPU doesn't care how the bits got organized. But LLMs can't just jump straight to the compiled output, they have to come back to the intermediary of human-readable language, and that means they're bound by the limitations of the languages we've asked them to write in. That also means that they write bugs and bad code because they're trying to produce readable tokens that possibly do the thing you ask, and they're not writing the code and testing it and refining it in a tight loop before delivering it.
When I write code, a function may see multiple passes before I even show it to anyone else. If you don't understand the output the LLM is giving you, but it compiles and vaguely does the thing that you ask, you might take it at face value on the first pass. And since the code is only receiving "yeah, that looks right," level scrutiny, it's so much more likely to be bad.