They are (again, most likely) acting in good faith and trying their best to assess technical skills and how someone collaborates, albeit it may be a somewhat broken system. Most companies in my opinion, don’t really know what else to do than the interview system they have always had, or how to fix it, so they just keep doing what their doing (and I don’t blame them for it, it may be too much time to re-work).
Finally, have humility, curiosity, and try to collaborate with your interviewers. If anything, you can learn a lot from a failed code interview and also make some good connections with interviewers. I have had scenarios where I fail the code/technical interview, but have been referred to other positions because I do my best to enter into the interview with the humility, curiosity, and a desire to collaborate with my interviewers.
Interviewing on both sides is hard. From what I have heard, there are interviewers acting in bad faith who just want to flex their technical knowledge, but for the most part, I would contend that is not the case.
Hope this helps, and best of luck to you!