Hold shift while starting up Safari from the dock.
Go to Develop menu and do Empty Caches. If Develop Menu is not there, enable it in Safari Settings under Advanced tab.
One can also dig in Caches folder in ~/Library and find the icons there.
This is a project I looked at some time back.
I’m pretty sure you need to start with the 1024x1024 size, and the system will scale it as needed.
There are programs (apps) out there like IconEdit etc, although that one may be a bit old now, that creates the proper file type.
Edit: I’m pretty sure the images or at least their names are stored in a control file ...