It's already mentioned in the 5e Monster Manual in the entry for skeletons that uncontrolled skeletons will do things they would often do in life:
Habitual Behaviors. Independent skeletons temporarily or permanently free of a master’s control sometimes pantomime actions from their past lives, their bones echoing the rote behaviors of their former living selves.
Would a necromancer be able to, more or less, tap into that and perhaps make a skeleton that acts in the way it would have normally in life? And is the same true for other undead?
I know it'd be difficult for the undead in question, as they may not know how they acted in life, but if the way they acted was disclosed to them, could they act in that way? And supposing that the necromancer dies, would they continue to act in such a way with the original order?
Rules as written are not very specific about how far a necromancer can order their undead around, only that they understand simple commands (in the case of undead like zombies or skeletons) and that other intelligent undead, while they can be put under the thrall of a master necromancer, often fall into habits from life despite having some autonomy. So if an undead was given a hat of disguise and told to act like a human, would they be able to at least pass by with the disguise?
Best Answer
It's largely dependent on the undead in question, and at times on the DM.
As you mentioned a necromancer being involved, I will first address undead minions available to playable necromancer wizards through spells: ghasts, ghouls, mummies, skeletons, wights, and zombies. Those are also the common undead minions of undead NPCs. I will refer to the entries presented in the Monster Manual, as monster description are as important as their stat blocks. Emphasis within this answer is mine.
As an extra note: generally, in D&D, most of the things that give a creature its personality and memories is just their soul. And most undead are not created using their soul: they are cadavers animated by magic of some sort. Some aspects of the soul can still linger in some undead, whilst some others might have a (trapped?) soul within their body.
Ghouls and Ghasts: up to the DM.
The entries for the ghoul do not refer to it directly, but it is inferred they keep memories, or can keep them, through their "origin story". We gather from this that at the very least the original ghoul Doresan kept its memories of elven deities after having served Orcus, the responsible for his transformation. Though this gives not clear cut answer for every ghoul. However, a ghast is described as being more cunning than a ghoul, depicted as a "little more than a savage beast". We can imply that, even if ghouls can keep memories, the ghast is the version of ghouls that ultimately could reminisce more clearly or act on those.
Mummies: Yes, but...
In essence, mummies became slaves through the rite performed to make them undead. The second to last paragraph, however, tells us they do, in fact, keep their memories.
Skeletons: No. But still...
We get some info about it throughout their description (please, do not use their Intelligence score as a basis):
The "but still..." part refers to this other section:
I'd say an uncontrolled skeleton is presumed to start acting on former memories, but even with a hat of disguise, that undead cannot speak.
Wights: Yes.
Sadly, that's all we got for wights, but it seems enough to give a clear answer.
Zombies: No. Period.
That being said, those are just the common undead minions. Undead can be extremely varied and/or even independent. As an example, vampires are said to either keep or not keep memories from their former lives, and those memories they do not keep cling to them in the form of "cravings", such as surrounding themselves with art pieces. And even then, a DM can always rule otherwise.
What I'm writing here is the RAW interpretation of undead that in a generic campaign a playable necromancer might command. If you need more information about individual undead creatures, their description might give you an answer or a hint; if not, ask your DM (or come up with an interpretation, if you are the DM).