The article below contains a long list of cases where courts determined peoples sexualities and punished them. I agree, it is absurd. All religious law is.
https://en.m.wikipedia.org/wiki/LGBT_rights_in_Saudi_Arabia
There are similar articles for dozens of other countries.