There are a lot of excellent developers who do not code well in an interview context. Nerves, artificial restraints... coding is something that happens once you're in the flow. That's a state few can achieve in an interview.
Yes, nerves play a part. That's why it's good to start easy and ramp up difficulty gradually, giving the interviewee a few easy wins to build up their confidence before getting them in to the harder stuff.
Frankly I find the most unnerving interviews (coding and questions) to be the ones where you have to second guess what the interviewer wants to hear. Where the question/task is difficult, but the desired outcome straightforward it's much less stressful.
That's kind of like how I code when sitting down for an interview, whereas I have no problem otherwise. My coding looks like an awkwardly told joke (oftentimes).
If all I had to do was pick some code I had memorized and practiced and "perform it", i.e. type it out, then yeah, sure, no problem. But I get asked to come up with the answer to something on the spot, something I usually take a little time to settle into, maybe do some Googling, etc, and always seems to be something I missed when spending several days to a week refreshing my memory on what I think I'm going to be asked ahead of the interview.