\textbackslash is a text-mode command, so it does not work in math-mode (as you may have noticed) because math fonts are wildly different from text fonts, so the characters are set up differently, so they are not at all compatible. in math-mode you'd use \backslash if you wanted the backslash math symbol.
Though your command:
$\textbackslash$def $\textbackslash$cp $\{$ $\textbackslash$ textit$ \{ $ cp.$ \} $ $ \} $
looks a lot like you are trying to typeset some LaTeX command. Then just use \verb:
\documentclass{article}
\begin{document}
\verb|\def\cp{\textit{cp.}}|
\end{document}

As a rule of thumb: if it's too complicated, you're doing it the wrong way.
listingspackage. Orminted. – Teepeemm Feb 11 '20 at 04:50