There are some long lists of false beliefs that programmers hold. isn't because programmers are especially likely to be more wrong than anyone else, it's just that programming offers a better opportunity than most people get to find out how incomplete their model of the world is.
I'm posting about this here, not just because this information has a decent chance of being both entertaining and useful, but because LWers try to figure things out from relatively simple principles-- who knows what simplifying assumptions might be tripping us up?
The classic (and I think the first) was about names. There have been a few more lists created since then.
Time. And time zones. Crowd-sourced time errors.
Addresses. Possibly more about addresses. I haven't compared the lists.
Gender. This is so short I assume it's seriously incomplete.
Networks. Weirdly, there is no list of falsehoods programmers believe about html (or at least a fast search didn't turn anything up). Don't trust the words in the url.
Distributed computing Build systems.
Poem about character conversion.
I got started on the subject because of this about testing your code, which was posted by Andrew Ducker.
So there are specific contexts in which taking people's expressed gender identity at face value would work badly. Fair enough. But as the saying goes, "hard cases make bad law"; the question "are there contexts where doing X works badly?" may be less appropriate than "in most contexts, does doing X work better than not doing X?". It could be that (1) letting allegedly transgender criminals get moved to different prisons on the basis of their "new" gender is a bad idea, but that (2) outside prison, taking allegedly transgender people at face value is generally much better than not.
Still, let's consider that example a little more carefully. It's certainly true that we would prefer not to have male criminals get themselves put in all-female prisons just by saying "I'm a woman now", because they might endanger the other inmates. So, you do two things. First, you don't let people switch gender simply by saying "I'm a ---- now". Perhaps, e.g., you (1) require an official diagnosis of gender dysphoria (this will eliminate some would-be abusers, but no doubt some will be convincing enough to pass this filter), (2) don't switch anyone into a [new gender] prison unless they've got as far as a course of hormone treatment (this will eliminate most remaining would-be abusers, I think), and (3) as I think is commonplace outside prison, you don't let them have that hormone treatment until they've lived for an extended period "as" their newly adopted gender. New name, new clothes, etc. (This is part of why #2 is an effective filter, though the effects of the hormones will be a bigger part.)
Second, you use the mechanisms that surely already exist for keeping prisoners safe from one another. For instance, surely some women are very dangerous to other women, and they are kept in solitary confinement or watched extra-carefully or something. So if, e.g., an apparently-male criminal abruptly declares "I'm a woman now" and gets through the filters above, maybe they have to put up with being treated as much more dangerous to (other) women than a typical woman in the prison they get sent to.
And of course if they do then (say) assault someone else, down comes the wrath of the law and the prison system on them, and their life thereafter is going to be really unpleasant. If they're calculating and controlled enough to convince a psychiatrist that they have a gender dysphoria they don't really have, and to put up with living as a woman and getting dosed with anti-androgens and oestrogens and whatnot, they're probably also capable of figuring out that actually harming anyone is liable not to be worth the trouble.
All things considered, I don't actually see much practical opportunity for abuse here -- and this is the example you picked.