The attack is wasted if there are no other creatures nearby, assuming the saving throw against sanctuary is failed.
If you're attacked first, then sanctuary activates. Assume the creature fails its save, because if it passes, the question is moot. The only available target is your mount, which it then chooses to attack. Mounted Combatant can then be used to force the attack to target you again. If the creature fails again, the attack is wasted, as the attack is forced to target you instead of your mount.
If your mount is attacked first, you can use Mounted Combatant to force the attack to target you instead. Sanctuary then activates, and the creature fails. It's unable to attack the mount again, because you've forced it to target you instead, but it's also unable to target you, so it's attack is wasted.
In both cases, after you've used Mounted Combatant, the mount is not a valid target, because the feat "force[s] an attack [...] to target you instead". Since this is the same attack, and it's been forced to not attack the mount because of this feat, it cannot be re-targeted, even after sanctuary applies.