I mean, obviously it’s possible for automata to behave in such a way that is indistinguishable from humans (including expressing joy, sadness, anxiety, pain, etc.), yet still be completely non-sentient. An outside observer would have no way of knowing (see the famous “Chinese room” thought experiment).
But we all know Star Wars isn’t thinking about this. C3PO exists for comic relief and nothing more. Actually, C3PO is basically just a sci-fi homage to a Kurosawa character.
But since C3PO is designed for etiquette and protocol, it kind of makes sense his designers would incorporate many human-like qualities, including expressing a range of emotions.