I think you are using the code in this article to upload a file:
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/upload-a-file-by-using-the-rest-api-and-jquery
In fact, the code will upload the file then change the file name after uploading. When uploading, it will replace the exisiting file if a file already exists.
However,if you try to change the name of the file with existing files'. You will get this error.
For example:
I have a file with name aa.xlsx in the library:

I upload a file test.xlsx and try to rename it with aa.xlsx. I would get this error.

Infact, the file test.xlsx is uploaded successfully, but we cannot changed it name with aa.xlsx.

As a workaround, you could rename the file (test.xlsx) in the local machine (aa.xlsx). Then upload it. Just do not enter the name for the file.

It replaced the existing aa.xlsx.
