The pattern of behavior you are describing is called psychological reactance.
Reactance as a concept has been formalized in Jack Brehm's work in the 1960s, who has proposed a Theory of Psychological Reactance (1966). The theory posits that threats to personal freedom cause motivational arousal directed at reestablishing freedom. Consequently, the attractiveness of those behavioral choices that are eliminated or threatened can be increased.
A textbook example is a study (Brehm, Stires, Sensenig, & Shaban, 1966) in which students were promised to choose one of several music recordings. When one of the alternatives was taken away, it was perceived to be more attractive (but only when the students had the expectation that they could decide freely).
Since then, the concept has been applied to a wide variety of settings such as the role of eliminated freedom in consumer behavior (e.g., Clee & Wicklund, 1980), the persuasive effects of promotional health messages (e.g., Dillard & Shen, 2005), or patient noncompliance in therapeutic settings (e.g., Fogarty, 1997).
References
Brehm, J. W. (1966). A theory of psychological reactance. New York: Academic Press.
Brehm, J. W., Stires, L. K., Sensenig, J., & Shaban, J. (1966). The attractiveness of an eliminated choice alternative. Journal of Experimental Social Psychology, 2, 301–313. doi:10.1016/0022-1031(66)90086-2
Clee, M. A., & Wicklund, R. A. (1980). Consumer behavior and psychological reactance. Journal of Consumer Research, 6, 389–405.
Dillard, J. P., & Shen, L. (2005). On the nature of reactance and its role in persuasive health communication. Communication Monographs, 72, 144–168. doi:10.1080/03637750500111815
Fogarty, J. S. (1997). Reactance theory and patient noncompliance. Social Science & Medicine, 45, 1277–1288. doi:10.1016/S0277-9536(97)00055-5