How Finder tracks location of items in the sidebar In Windows File Explorer if I create a shortcut to a folder on the disk and then rename/remove/move to trash the folder I will be no longer able to click and open the link.

On Mac if I drag a folder to the Finder sidebar and then do the same operations with the folder, Finder will track it somehow and let me open the folder even if I move it to the Trash.

What macOS API is responsible for this?
I'm not sure if there's an API for it, per se, it's simply the way it operates. Items in the Finder sidebar are actually aliases to the original item.
From What Are Aliases, Symbolic Links, and Hard Links in Mac OS X:

When you create an alias for an object, the system creates a small data file that includes the current path to the object, as well as the object's inode name. Each object's inode name is a long string of numbers, independent of the name you give the object, and guaranteed to be unique to any volume or drive your Mac uses.
...
When you access an alias, the system checks to see if the original item is at the pathname stored in the alias file. If it is, then the system accesses it, and that's that. If the object has been moved, the system searches for a file that has the same inode name as the one stored in the alias file.

(Or do you mean an API that allows you to create aliases from your own application?)