Spells such as Regenerate and Heroes' Feast (and probably others that I've missed, too) can heal undead, however I don't think that that's the real answer here.
The first answer is that undead can rest, just like anyone else. MearlsCrawford tweeted on this: https://www.sageadvice.eu/2014/09/19/undead-short-rest/ It doesn't mention long rests, but I think it's safe to assume that if they can take short rests, they can take long rests, too. So they have the same option for restoring health as any other non-spellcasting character or creature.
The second answer is that most powerful, sentient undead have a backup plan in case of death. It's often the reason they became an undead in the first place. Vampires, mummy lords, and liches of all kinds all return to life if they are reduced to 0 hit points unless adventurers manage to prevent them.
Many powerful dead have ways of healing themselves on top of this, usually at the expense of others. Vampires and demiliches suck the life out of their victims, and vampires continually regenerate on top of everything else.
So while spells that can heal the undead are indeed in short supply, the simple answer is that most undead don't really need them. Also consider that even if Cure Wounds and other spells like it could heal undead, those are spells that most undead wouldn't have access to anyway.