When you tell someone not to do something, are they going to listen; or are they more motivated than ever to do it? Science would say that the latter is more likely, because people like to be in control of their own lives.
The behavior is purely psychological and is known as reactance, which is a type of mechanism where our brain wants to ensure that we're free to do whatever it is that we want to do with our own lives.
But that's not all; humans are also notoriously curious creatures, so when you label something as the forbidden fruit and then say someone can't have it, you ultimately make them want it even though they might not have even wanted it to begin with.
This is particularly the kind of psychology that's also used behind click-baity titles in videos on YouTube. When you see a title that challenges your intelligence by using words like "you won't believe" or "you don't know," the brain is automatically challenged to say otherwise, and makes you want to watch the video even more, just to prove it wrong.
There are a lot of factors that can impact your impulse to do things you're told not to do, including genetics, but most of the time the psychology and physiology behind it all is the main cause.