Does "51" meaning crack cocaine have any relation to police code "5150"?
What might be called 'disambiguation' in other contexts is, in the context of drug use and abuse terminology, more on the order of 'deobfuscation'.
The mixture of '151', '5150' and '51' has some stupefying characteristics in common with the most usual reference of '51', that is, a
combination of crack cocaine with marijuana or tobacco.
"Crack Cocaine Street Names", SoberRecovery, 12 Mar 2015.
The use of '51' in this sense is either an easy-to-speak-while-jonesing street slang obfuscation-via-truncation of '151' in the sense of 'cocaine', a term itself shortened from the ICD-10 (International Classification of Diseases) diagnostic code F14.151 (late 1980s and early 1990s), which refers to "cocaine abuse with cocaine-induced psychotic disorder with hallucinations", or the similar shortening of '5150', which last refers to the 5150 section of the California Welfare and Institutions Code, or both. That section of the California WIC authorizes the temporary detention of "Mentally Disordered Persons for Evaluation and Treatment" if they are deemed "a danger to others, or to himself or herself, or gravely disabled".
Most likely is that the coincidence of '51' appearing in both the ICD-10 diagnostic code and the California WIC section played a part in the street adoption of the term.
Other influences may include '5-1' in Roman numerals being the heart of EVIL (VI), symbolic use of the '5150' code by heavy metal bands and rappers of the 1980s and 1990s (for example, Van Halen's studio, song and album of that name), and the confluent history of crack cocaine use in the US, which peaked during the same time period (1980s and 1990s).