I believe it's called stimulus discrimination
Stimulus discrimination happens when two different responses happen for a same stimulus.
For example, when you tell dirty jokes to a close co-worker you would most likely get a laugh as a reaction. But if you tell the same joke to Human resources, you would most likely get into trouble.