This is common in sex crimes: see situational sexual behavior.
Another example is violent crime. Many violent criminals are only violent in certain contexts. For example, they may be violent towards their families but not in the outside world, or vice versa. Some violent criminals are only violent in very specific contexts (for example, football hooliganism) and do not commit violence outside of that context.