The spell has no effect if following the command is directly harmful
Command says:
You speak a one-word command to a creature you can see within range. The target must succeed on a Wisdom saving throw or follow the command on its next turn. The spell has no effect if the target is undead, if it doesn't understand your language, or if your command is directly harmful to it.
There is no rule that the effects of a spell only are checked at the time of casting, and in general, consensus is that spells continue to check if they apply, (and are only suppressed while their target is invalid).
So, if at the time of the creatures action, the action is directly harmful to the creature, the spell has no effect and the creature will not take the action.
In your example, the mob would not move through the spike growth.
P.S. Note that spike growth says
The transformation of the ground is camouflaged to look natural. Any creature that can't see the area at the time the spell is cast must make a Wisdom (Perception) check against your spell save DC to recognize the terrain as hazardous before entering it.
Command does only say the spell must be directly harmful to the creature, not that the creature has to be aware of it for the spell to have no effect, so as written, it would fail even if the creature would not know that the command is harmful.
A DM could favor an interpretation where the spell has no effect because the creature is aware the action would hurt it. If they ruled on the spell like that, then the spell only would have no effect if the creature succeeded on their perception check that the area is covered in sharp spikes.