I know it's not canon but there is an explanation that I think really fits that David Mack gives in his Star Trek: The Next Generation: Cold Equations trilogy...
I think that explains how he could be confused by Barclay's performance and the audience's reaction to it and then have that situation prompt his response. I do think it was more confusion than irritation, it may have just not quite come across entirely clear. He was confused as to why the crowd was reacting in a way that he perceived to be an over-reaction.
From a production standpoint, if Data were to be truly emotionless the writers would be forced to make him essentially a boring, simple, dialogue delivery system. He would be able to provide ideas, facts, and information to the crew but little else. I don't see how he'd even be able to interact with the crew in any interesting manner. I think they wanted to make him still an interesting and compelling character so gave some leeway with his "emotional" range. Even his desire to become more human, his ability to be interested in anything at all shows that he has some level of "machine emotions" even if they aren't the full range of human emotions.
A certain character in the book describes how Data having no emotions is inaccurate and that he has "machine emotions" but not "human emotions." Machine emotions are described as Data's desire to learn, his desire to become more human, his curiosity, etc. as opposed to complex human emotions such as love, hate, sadness, fear, happiness, etc.
I think that explains how he could be confused by Barclay's performance and the audience's reaction to it and then have that situation prompt his response. I do think it was more confusion than irritation, it may have just not quite come across entirely clear. He was confused as to why the crowd was reacting in a way that he perceived to be an over-reaction.
From a production standpoint, if Data were to be truly emotionless the writers would be forced to make him essentially a boring, simple, dialogue delivery system. He would be able to provide ideas, facts, and information to the crew but little else. I don't see how he'd even be able to interact with the crew in any interesting manner. I think they wanted to make him still an interesting and compelling character so gave some leeway with his "emotional" range. Even his desire to become more human, his ability to be interested in anything at all shows that he has some level of "machine emotions" even if they aren't the full range of human emotions.