It depends on the details of the case, but in both of your examples, yes, they do stay immune. Both Undead and Constructs have "immune to mind-affecting)affecting" as a creature-type trait, listed independently of any tendency for many creatures of that type to be mindless. Thus, even a creature of these types who is not mindless still has this immunity. However, if the creature does not have any such Intelligence-independent trait granting them immunity, and is only immune via the
Blockquote MindMind-Affecting: Mindless creatures (those with an Intelligence score of “—”) and undead are immune to mind-affecting effects.
clause in the magic rules (for example, most Oozes), then no, they would not retain their immunity if granted an Intelligence score. (Note that, in the Ooze's case, at least, this exception is explicitly called out in their version of the Mindless creature-type trait.)
Presumably, the minds of undead and intelligent constructs simply function, mechanistically, in ways sufficiently differentlydifferent from the functional mechanisms of organic minds, to not be manipulable by the same effects.