He was only looking out for Frodo! There was maybe ONE time when Gollum didn't deserve the way he spoke to him, but really...you never knew whether he was good Gollum or bad Gollum at any one moment! Can you blame Sam for being suspicious, especially when Frodo and the whole quest were at stake?