First, the standard spelling lookup doesn’t offer homonyms. So much for that idea.
In a rudimentary search, it appears that it would involve using the Mac OS Dictionary Services API, and a downloadable dictionary. Ideally one would avoid using an online dictionary for lookups, because of speed and connectivity factors.
I know there are alternate dictionaries you can install; foreign language, medical, or legal, for example. It seems reasonable that a homonym dictionary is available, then the PopClip function could use the Dictionary Services API to specify that dictionary? I’m over my head here, so just guessing.
For Swift, I found this: Apple Developer Documentation
Apple has done away with a lot of useful functions like being able to add custom words to your own custom dictionary. I miss that.