Because they don’t represent real world situations.
Nobody remembers everything that they have worked on. Typically, anything that I haven’t worked on for the past 6 months, I forget but once I am back working with whatever that is regularly, it comes back quickly like riding a bicycle.
In these situations, I make regular use of stackoverflow and other google related searches. Can’t do that in a coding interview. You are expected to know “everything” since you don’t have any idea of what the question would be. That’s not realistic and nobody is going to know that unless they have studied and prepared for weeks and weeks like they are taking a final. And then once they have “passed”, they will forget 90% of what they have learned within a few weeks.
At the end of the day, these interviews prioritize people who crammed for the interview like they did for a final exam and not people who actually build solutions and architect them on a higher level day in day out.