Most ideas for Hard AI (human level learning AI) involve some form of genetic programing or other 'growth' algorithm. These algorithms could lead to identity crises. But first let me explain a little about AIs in general, keep in mind I'm over simplifying some details here:
Right now our 'AI' that we write is mostly soft AI, and it is not really intelligent. It simply has a list of rules that says things like "if x then do Y unless Z", with a bunch of probabilities, random number generation, and game theory thrown in. Still, the point is that right now with soft AI we can only do things we explicitly programed. If I never programed a rule for what to do if situation A comes up my AI will never properly handle that situation, no matter how often it comes up.
The limit here is obvious, this AI can't really learn or grow. I can write rules that allow some limited form of quasi learning, like "see how many times X happens if you do Y and Z, and do either Y or Z depending on whichever caused X to happen more often", which allows my AI to 'learn' that either Y or Z is more effective if I want X; but this is a very limited form of 'learning' that had to be programed in. Humans simply can not program in the kind of rules required for truly intelligent hard AI, there are too many situations to write even if we could think of them all.
Hard AI is more like the AI you read about in science fiction, intelligence that thinks and learns like humans. In sure actual intelligence, not a bunch of rules faking it.
As I said the sort of rules based approach we currently use for Soft AI don't seem capable of producing this. Instead were looking at tricks like genetic programing and 'growing' of an AI for this....
Genetic programing is a simple idea in general, though it should really be called evolutionary programing, since it's inspired by evolution that drove our genetics. If you know how evolution works the basic idea is we have blue prints (genes) that occasionally get random changes (mutations). Most of these mutations were bad and killed those who got them, but a very small number were good and lead to stronger humans which passed on there genes. This basic concept evolved extremely complex beings like humans, something humans could never design on our own.
We use a similar idea in programing. Start out with a very basic 'program' and intentionally add random 'mutations' to that program, by changing parts of the code. Then run the resulting code through a suite of tests to decide rather or not the new code is closer to our desired goal then the old. Toss out code that doesn't work closer to a goal, keep 'mutations' that do until survival of the fittest code slowly leads to 'evolving' a program that exactly meets our desired goal.
The important idea here is that we DO NOT write the program itself. Instead we define the end state that we want the program to have and then set it lose to 'evolve' towards that goal. We don't know how it will do it. For instance a genetic programing attempt to build a radio once created one of the smallest radios...which worked by exploiting a flaw in the physical hardware to create signals in a manner that was never intended by the hardware itself! That particular example proved less-then-useful since we couldn't mass produce the flaw, but it did show that very unique solutions can come out of genetic programing that are different from how humans would ever design something.
It's believed that Hard AI will need approaches like genetic programing to work, approaches which do not attempt to define exactly how the AI should be created, but instead only encourage the AI to develop towards a final goal on its own. Our genetic programing approaches are still far to basic to produce a hard AI, and the final hard AI will likely use approaches complex enough to not be considered genetic programming, but they will likely build off the same concept. For instance one idea is to actually grow a silicon brain which models human brains and then develop an AI by effectively teaching a new brain the way we teach a newborn; instead of starting with a final AI we simply help the brain develop intelligence.
The Final Answer
This is all relevant because a side effect of genetic programing is that we don't actually know or control specifically how the AI develops its intelligence. Just like the example with the radio that worked only based off of a defect in it's hardware we may grow an AI that functions only through bizarre, and not always 100% desirable, means; but since we can't build an AI from scratch we need to settle for the best we can grow even if it has flaws.
TO give an analogy look at humans. Were a wonder of evolutionary engineering, but we have many 'bugs' due to evolution. Allergies are our own bodies sickening us with disproportionate defenses to harmless allergens, our brains have numerous logical flaws that cause us to misunderstand the world and make numerous mistakes (check Wikipedia for list of logical fallacies some time), and our pursuing short term pleasure can lead to long term suffering if not kept in check (addiction for example). We don't want these traits, but for various evolutionary reasons they were evolved for. Were stuck with them now. In much the same way an AI that we helped 'evolve' may have it's own quirks and limitations we would not have wanted, but are still an unavoidable side effect of their growth.
Therefore it's quite reasonable to presume that the same limits of our own brains would 'evolve' into an AI we grow; for exactly the same reasons these limits grew into our own brain. Confusion, pursuit of short term goals to the exception of long term, some 'logical fallacies' (the exact form may be different) could all evolve into a brain we grow. Thus any human conditions, including identity crises or even specifically gender dysphoria like you mention, are entirely possible with grown AIs; particularly in our earlier versions of hard AI (we may later learn ways to encourage evolution of AI hat avoids a specific undesirable side effect, but doing so risks evolving some other bizarre side issues).
It is possible each grown AI will have a 'personality' that results from their 'evolving' through slightly different steps as well, so an AI may very well assign itself a gender because it's evolution predisposed it towards certain traits that are associated with specific gender so it chooses to identify as that gender.
One key thing though, AI is still software. If we have to grow each AI from scratch (instead of growing a few and then mass producing copies of those we grew) then we would likely have some way of testing rather an AI was functional after it finished growing. Like with the example of the smallest radio which could never be mass produced because it depended on a defect in the hardware it's possible that some AI will grow to meet our stated standards, but prove to not actually be functional or useful (imagine an AI which grew to be every bit as smart as we wanted, but for some reason was suicidally depressed and only wished to end it's own life, perhaps a bit excessive of an example, but you get the idea). An AI with an identity crises will likely be seen simply as an AI that was 'grown' wrong, and best replaced with a newly grown AI...