Idiom
if someone knows what's good for themif (someone) knows what's good for (them)
if you say that someone will do something if they know what's good for them, you mean that they should do that thing or else something bad might happen to them.You'll obey my orders if you know what's good for you.