Try to put yourself in your son's situation. Try to understand where his behaviour is coming from. If you manage to ask the right questions, he may well be able to articulate this, you haven't told us much about how you communicate around this when there isn't an acute issue. I try to do debriefing with my oldest in a low-arousal setting, when the conflict is not ongoing.
The only thing we can be fairly certain about is that there is a reason for the behavior. Someone has pointed to a neurological condition as a possible reason in comments, but I personally think that's very far reaching given the little info we have, but there is some explanation. People aren't always rational but we rarely act at pure random. Finding that cause will naturally be key to coming up with useful solutions. And the motives driving children's behaviour is often far removed from how we as adults would approach the same situation, because they don't have as large a problem solving toolkit, so we don't need to confine ourselves to good reasons.
I am inclined to believe there are clues in how you interact as families. To a 3.5-year old, a 6 month toddler can be a cute doll to play with, who then mostly sits there when you don't want to play, while a 2-year-old may well be in an interim age where they are too young for meaningful play (and keep in mind that you may think that the cousin is a good playing partner, but you may be better than your son at discounting for the cousin's young age and adjusting your expectations and mode of play accordingly) while at the same time no longer just a harmless blob and but an actual interfering agent. Your son may well make a completely valid conclusion that the incentive for sharing toys and engaging in play with this child low. Your son may then lack the adult skills of setting his own interests aside and being the bigger person, and non-violent conflict resolution.
If you know that that's the issue, those are skills you can help him develop and give him better tools for. Just knocking down on his solution without acknowledging the perceived problem may just come across as invalidating his problem. If violence is the only solution he can conceive to his problem, saying that he can't use violence may be heard as he's wrong to feel the way he does.
I'm suspecting that your child gets along fine with younger kids in daycare because they're not expected to connect very deeply, and playing separately is not an issue. With cousins, there may be an expectation from the parents that the kids should get along very well that is simply beyond the capabilites of young children. With time, that age gap will diminish, and so may the problem, but for now, ask yourself if you are applying pressure on the cousins to engage in a manner that isn't currently very rewarding to them.
Regardless of whether that's the actual issue at hand, I think these are the questions you must ask yourself, and this is how the problem must be approached.
Don't just say "You can't hit him, that's not nice". Yes, interrupt the violent situation immediately (and say that this behavior makes you sad, avoiding which is a more meaningful outcome to your child than an arbitrary ideal of being nice) but as soon as you are no longer in the heat of the conflict, say "I saw that you were hitting your cousin. That makes me sad, because I really don't think that's how we should treat one another. It looked as though you were angry that he was going to take your toys? How do you feel when he does that?"
If your son keeps resorting to violence, chances are he doesn't even find his solution to his problems to be very effective, and maybe he'll happily abandon them for something better.
You say that he mentions his cousin out of the blue, and says that when cousin does X, he will respond with Y. I honestly think that is amazing. It suggests to me that your son trying to initiate the debriefing sessions you need to have, in a low-arousal setting, outside the heat of the moment. Don't shame or scold him in that instance, for having said he'll do a bad thing, validate his feelings and ask questions about what is going on in those conflicts.
Oh, and don't expect miracles. I'm hopeful you'll be able to walk through the situation with your son and agree on new approaches, but there won't be a eureka moment after which your three year old is a master conflict resolver. Once you agree on a desired behavior, it'll be your responsibility to remind him and help him exercise that behavior, until it comes naturalky to him.