Are directional instruments like an HSI or AHRS immune to magnetic compass error?
The short answer is yes, but for different reasons.

The analog HSI in most aircraft that have them either has an internal directional gyroscope, or it is slaved to the directional gyro (more often the former than the latter as the HSI often replaces the DG). An analog DG/HSI must still be periodically corrected for precession error by levelling off, letting both instruments stabilize and then adjusting the HSI's card to the magnetic compass.

AHRS systems that power glass cockpits use a solid-state directional gyro that is corrected by a magnetometer (an antenna device that directly senses the relative direction of the magnetic field) rather than a floating magnet. This makes them impervious to the types of error commonly seen in floating compasses such as acceleration bias (which causes all the behaviors you mentioned). They can still be sensitive to nearby ferrous metal structural members and to electrical currents, requiring a digital version of "spinning the compass" with corrections input into the software that uses the magnetometer readings, and magnetic declination must also be accounted for (either mentally by the pilot, manually based on declination charts or in more sophisticated systems by directly incorporating position data from the GPS).