He was eating ice cream.
"Don't dirty your shirt."
Does it look grammatically correct and sound natural?
I heard it from someone. Does it mean make sure not to make your shirt dirty?
There is a verb "to dirty" something but it is not often used. Instead it's more common to use "to get (something) dirty."
The laundry got dirty when he left them out in the rain instead of taking them down from the clothesline.
The children got dirty from playing in the mud, then tracked it all through the house.
My new shirt got dirty when I accidentally spilled coffee all over it.
So in your example:
Careful eating your ice cream. Don't get your shirt dirty.
As Mare Maneski points out in another answer, "to soil" is also an option. I don't think it's as commonly used as "to get dirty" but some people might feel it's the correct word to use in this situation:
Don't spill your ice cream and soil your new shirt!
As with all your previous questions, the real challenge is that the action you choose to admonish your son about is not the action many native speakers would choose. In this case I wouldn't warn the child not to get his shirt dirty, I would warn him not to drip or spill or drop food on his shirt.
Use a napkin so the ice cream won't melt all over your shirt!
Look, you're dropping it all on your shirt and you're making a mess!
And so on. It's the action that causes the mess that I would warn about, not just the mess itself.
Yes, "to dirty" is a verb. But "to soil" seems more common.