Shafu was a living being, so the ghosts could affect it. However, Noah didn't have to worry about separating reality and illusions when it came to his companions since the mental connection would tell him when something was off.
The rank 9 cultivator's eyes widened in surprise when he saw Shafu's massive mouth closing on the entire army of ghosts and bringing them into the separate space inside its body. He didn't sense the arrival of the dragon at all. Noah had relied on the Shadow Domain to make it appear in the area.
Shafu made sure not to destroy the creatures during the process to limit the spreading of their dark energy, and Noah kept the mental connection in check to confirm that everything worked as planned. The ghosts ended up at the center of his companion's separate space without affecting its mental state, but they immediately tried to spread their influence.