Let's take drugs for an example but this can apply to other behaviors like internet usage, eating, falling in love, becoming obsessed with a hobby, or cronic anxiety toward something (avoiding fear). When we take a drug (or do xyz behavior ) it gives us a positive feeling (pleasure, or comfort in avoiding fear) and probably a favorable outcome occurred, so we are likely to engage in the behavior again. Each time we engage in the behavior the connection between the limbic system and the stimulus that triggers it, strengthen. When the trigger happens the limbic system lights up and triggers the PFC to create a plan and imagine how good it will be (then a positive feedback will occur - this is craving). Over time more and more stimuli will become triggers. Also, if you don't use it you lose it, and the neurons responsible for long term planning will weaken their connection to the limbic system (also, shown in brain scans), making it harder for you to assert self control.
However, your brain is plastic, and you can also unlearn the behavior over time (studies also support this). Meditation can help because you can stimulate these neural pathways in a controlled environment. For example you can imagine how a trigger leads to drugs, then you can imagine how drugs leads to bad things while meditating - over time you can strengthen the connection from the trigger to the emotion and imagery of bad things happening. Ofcourse meditation is not the only thing that can help, but the main idea is that you want to make your brain associate the bad behavior with bad outcome, and strengthen the association of good outcomes with fear/desire circuit.
Book: The Biology of Desire: Why Addiction Is Not a Disease - https://www.amazon.com/Biology-Desire-Why-Addiction-Disease/...
Youtube: The Neuroscience of addiction - https://www.youtube.com/watch?v=aOSD9rTVuWc
Edit: typos