If the target spell is an illegal target when Countermand tries to resolve, Countermand won't resolve and none of its effects will happen. The target's controller won't put any cards from the top of their library into their graveyard.