I don't think this is your book, but I'm posting this as a partial answer that matches the title so that it might help further querents. When I was in high school, I read John Peyton Cooke's The Chimney Sweeper, which is indeed about a gay policeman, but it's a standalone novel and it isn't set in Scotland.
... Kinky gay noir mystery which is not porn but has it darkly erotic moments. A drifter who is homophobic (clearly because he is fighting his same-sex urges kills a transvestite who has tried to force him to have sex, stuffs her body up a chimney in an abandoned house, and leaves town. A couple of years later, as he slowly gives in to his attractions, he is now a kept man and an openly gay cop--though he still doesn't not identify as gay personally--in that town. When the body in the chimney is found, he fears he will fall under suspicion. All the erotic scenes in this novel are tied to perversity of some sort, and the central character is very well written. However, the last quarter of the book goes so over-the-top (bondage leading to threat of emasculation) that I found myself chuckling where I clearly should not have been. Still, the overall atmosphere is compelling and memorable, and I look forward to reading more by this author.
If you only read the earlier parts of the book, it starts with the protagonist's high school years, where he has an older female (I can't remember if it was a neighbor or his mother) making casts of his penis to be made into either female sex toys or candles meant to be used as such, and there's a non-consensual scene where he believes that a teacher at school wants to have sex with him, so he forces her into it, seemingly to no future repercussions.