Injecting heroin

When someone injects heroin, how does it cross there blood-brain barrier?

Very quickly.

Seriously, the blood-brain barrier is not completely impermeable - if it were, you wouldn’t be able to get any oxygen (or remove any carbon dioxide) from the brain. Its function is primarily to keep out relatively large items like bacteria and what not. It is easily traversed by small molecules, including simple opioids and other pharmaceuticals.

(ETA: It’s been a long time, but IIRC, it helps that simple opioids are fat soluble, which causes heroin to metabolize to morphine very quickly.)