Is it possible to get a Raspberry Pi zero to wake a computer over a USB connection?
Bit of background first:

Generally, USB itself is not a bus over which a device can be really woken up if it stopped working completely, because it's a host-polling based bus, i.e. the host PC must inquire the keyboard in regular intervals. If that host is completely shut down, nothing one can do.

However, being a host for a USB keyboard is relatively easy, and since host firmwares need to emulate PS/2 (or Apple desktop bus keyboards) for compatibility reasons, anyway, that was a feature easy to implement: simply let the firmware take over the USB bus, and ask all the attached Human Interface Devices (HIDs) whether they got input every couple milliseconds.

So, all you'd need to do is implement a HID gadget profile on your Pi.

Yes, that works, and it's about the easiest profile to implement.

Whether that is a sensible approach is a different question alltogether: The Raspberry Pi, when it comes to ARM SoC computers, is a relatively power-hungry device, so that it is actually worth the question whether running a Pi 24/7 to wake up a computer is worth it – if that computer is attached to a router via ethernet, for example, that could use magic Wake on LAN packets instead.