Four is too young to differentiate ADHD from the challenging end of normal, anyway. It could also be some other root, like anxiety (meaning he's trying to control his environment to make the anxiety go away) or just something completely developmentally normal, like the Lawyer Phase, or the thing where they are sort of aware they have two conflicting emotions but they don't know how to explain it, so they say something completely confusing.
Or the ice cream example makes me think maybe he's starting to be able to hold sequential ideas in mind but finding processing this a bit tricky (go to car, but first, ice cream - if you think about it, this is a bit confusing if you are a small child, as the events will happen the other way around so they need to order it in their head to understand the full meaning.) For a younger child this wouldn't matter, because they're not doing it at all - the car is totally pushed out of their mind as soon as they hear ice cream.
Or it could be related to development of cognitive flexibility which is being able to quickly switch tracks mentally. In car mode - no, ice cream mode!! But then he's stuck on the car so says no ice cream, but then he actually DOES want ice cream so he says that. Or it could be when he says no ice cream he knows that signals the end of the day and is trying to say "I don't want to go home" but it comes out wrong.
I think with any developmental phase, some children seem to go through it in a very intense way whereas others seem to breeze through it and you barely notice at all.
I mentioned ADHD because it's my experience, but I don't actually think it's helpful to get too caught up in whether or not someone is within that bucket or not. I just mentioned it because sometimes people go "Aha!! Yes! The validation I've been looking for!" but equally some people can go "No, that's definitely not relevant to me" - labels are tricky.
Also - the other thing it makes me think when a child is just being contrary seemingly for no reason is that you're just seeing their brain getting a bit frazzled, especially if it's happening at the end of a long day or in relation to something associated with a strong emotion (I would call this "brain frazzle" dysregulated, but that's a whole can of worms because I see people use regulation/dysregulation language all over the place with meanings that I don't think are quite my meaning, but they use it as though it's a well-known term anybody would understand, and I know there was a point where I didn't know it, because it was so revelatory to me when I first did.)
In that scenario if the ice cream stand is fairly close I think I probably would ignore a bit or just sort of mentally note that, of course, he DOES want an ice cream and not necessarily take his words totally literally, but perhaps sort of mentally note that we may want to leave a bit earlier next time before he gets into the totally frazzled state. Or accept the frazzled state as part of the cost (right now) of a longer day out - which it might well be. Or look to manage it next time by bringing snacks and drinks and looking for a toilet break halfway through for example.
If you have the energy and brain space you could be silly with it like joking that he wants an ice cream but no ice cream, hmm shall we get you an invisible one? Or empathetic guessing at what the no-ice-cream part means e.g. not wanting the day to end "You've had a lovely day and you wish you could stay playing instead of getting an ice cream. But you do like ice cream, don't you?" (How To Talk give wishes in fantasy is AMAZING for this BTW) "I wish we could stay here ALL NIGHT and install a magic ice cream machine on this slide here so we didn't have to leave the park."
I have to run so can't round the post off nicely but also these are really more best case examples. I do think the internet gives the impression you're meant to deal with every scenario perfectly all the time and that's just not realistic, nor is it a normal human relationship.