The criminal justice system can be considered to include Police Scotland; the Scottish Courts; the Crown Office Procurator Fiscal Service and the Scottish Prison Service.
Whether a transgender person is in contact with any of these sections of the criminal justice system as a crime victim, witness or suspect/perpetrator, they ought not to be subjected to transphobic discrimination.
Transgender people in contact with the criminal justice system (whether as victims, witnesses or suspects) often have major fears about the possibility of other people trying to use their transgender status to discredit their testimony in court. They are also often very concerned with potential invasion by the media of their rights to privacy about their gender history.
Implementing good practice in transgender searching and custody is of vital importance in order to avoid transgender people suffering undue distress, risk of harm from others, and/or loss of dignity.
You can read a guide to your legal rights as a trans person in Scotland and what to do if you face discrimination here