If I had a black son I would have said the exact same things to him. I trained my own daughter in "street smarts" because that is what any concerned parent does.
You do it for the safety of your own child.
You do it because you love your child and want them to be safe.
You don't do it because you are trying to "piss on the NYPD".
When you tell your child directly this stuff, yes, you are trying to protect them. When you, as the Mayor of New York City, public state this in an attempt to relate to the protesters, you have to assue there is going to be some blowback.
And just because you don't EXPECT to piss someone off, doesn't mean you are absolved of the RESPONSIBILITY for pissing someone off.