The extraction can't be done
Both Polymorph and Wild Shape tell their target to assume the new form's game statistics, which includes (Monster Manual, page 6) the creature's type (Humanoid, Beast, Fiend, et cetera). A PC is usually humanoid, but if they use Wild Shape or Polymorph, their creature type can change.
The Mind Flayer's brain extraction action specifically targets "one incapacitated humanoid grappled by the mind flayer". Therefore, beings that are not humanoids, even temporarily, cannot be targeted by this special attack. A shapeshifter druid is therefore relatively safe when mauling against a mind flayer in bear form!
Rules as written, unfortunately so.
You've found an interaction that seems undeniably correct from a strict reading of the rules. For example, should a magic item require attunement by an elf, and you are polymorphed into a frog, you no longer satisfy the attunement prerequisite of being an elf. You are unattuned. But before you implement this ruling in your games, there are some things to consider.
That said, a number of arguments have been presented to the contrary in other answers that are worthy of consideration. In the proceeding sections, I note some undesirable outcomes from assuming that this is the RAW ruling, and give some general guidance for handling this question at the table.
This severely limits the utility of polymorphing yourself or your allies.
I have always assumed that you remain attuned to your magic items while polymorphed, and I am certain that the vast majority of D&D 5e games have ruled the same. Polymorph is a good spell. This ruling will make it quite costly. Every time you cast polymorph on yourself or your allies, those polymorphed characters have to spend a number of hours re-attuning to their magic items. This can be a significant cost if in a situation where you need those magic items to function. This cost can be so high, that it can turn polymorphing yourself into a last resort sort of option.
Discuss this with your tablemates and come to a collective agreement.
So what do you do? In my estimation, this ruling would add exactly zero fun to the game for me. I like polymorph. I like using, and would be pretty bummed out if I had to choose between being able to use my magic items and being able to use one of my favorite spells. This ruling would take away from the fun of the game for me.
But I am not going to pretend to speak for everyone; maybe you are into this kind of thing. Discuss this with your table, and come to a collective agreement about how polymorph is going to work. In my experience, even if only one character can cast polymorph, everyone is going to be affected by it at some point and would have to deal with the consequences of this ruling if you put it into place.
Best Answer
The target quite definitely remembers who its allies are. For contrast, the Feeblemind spell reduces Intelligence to 1, and explicitly states that they still remember who their friends are and will fight to defend them. In general, animals tend to know who their friends are, sometimes more reliably than humans.
As for what it means for a beast with Int 2 to have someone's personality, that's more of a roleplaying issue which is difficult to define. I'd suggest thinking about the animals you are familiar with and how they express their personalities despite their lack of intelligence. I think most dog or cat owners would agree that animals have distinct personalities which can be very visible.